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

Segmentation fault on boolean kernels #116

Closed
dpanfilyonok opened this issue May 17, 2021 · 0 comments · Fixed by #121
Closed

Segmentation fault on boolean kernels #116

dpanfilyonok opened this issue May 17, 2021 · 0 comments · Fixed by #121

Comments

@dpanfilyonok
Copy link

dpanfilyonok commented May 17, 2021

Describe the bug
Exception when running simple kernel on bool.

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at OpenCL.Net.Cl.clCreateBuffer(IntPtr, OpenCL.Net.MemFlags, IntPtr, IntPtr, OpenCL.Net.ErrorCode ByRef)
   at OpenCL.Net.Cl.clCreateBuffer(IntPtr, OpenCL.Net.MemFlags, IntPtr, IntPtr, OpenCL.Net.ErrorCode ByRef)
   at OpenCL.Net.Cl.CreateBuffer(OpenCL.Net.Context, OpenCL.Net.MemFlags, IntPtr, IntPtr, OpenCL.Net.ErrorCode ByRef)
   at OpenCL.Net.Cl.CreateBuffer(OpenCL.Net.Context, OpenCL.Net.MemFlags, IntPtr, System.Object, OpenCL.Net.ErrorCode ByRef)
   at Brahma.OpenCL.Commands.RunBase`1[[Brahma.OpenCL._1D, YC.Brahma.OpenCL, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].ArrayToMem(System.Object, System.Type)
   at Brahma.OpenCL.Commands.RunBase`1[[Brahma.OpenCL._1D, YC.Brahma.OpenCL, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].ToIMem(System.Object)
   at Brahma.OpenCL.Commands.RunBase`1[[Brahma.OpenCL._1D, YC.Brahma.OpenCL, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].SetupArgument(System.Object, Int32, System.Object)
   at DynamicClass.lambda_method(System.Runtime.CompilerServices.Closure, Brahma.OpenCL.Commands.Run`1<Brahma.OpenCL._1D>, Int32, System.Object)
   at Microsoft.FSharp.Collections.ArrayModule.IterateIndexed[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Core.FSharpFunc`2<Int32,Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,Microsoft.FSharp.Core.Unit>>, System.__Canon[])
   at DynamicClass.lambda_method(System.Runtime.CompilerServices.Closure, Microsoft.FSharp.Core.FSharpFunc`2<Int32,Microsoft.FSharp.Core.FSharpFunc`2<System.Object,Microsoft.FSharp.Core.Unit>>, System.Object[])
   at DynamicClass.lambda_method(System.Runtime.CompilerServices.Closure, Microsoft.FSharp.Core.Unit, Brahma.OpenCL._1D, Boolean[], Boolean[])
   at GraphBLAS.FSharp.Backend.Common.Copy+copyNonEmpty@28-1[[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(Microsoft.FSharp.Core.FSharpFunc`2<Brahma.OpenCL._1D,Microsoft.FSharp.Core.FSharpFunc`2<Boolean[],Microsoft.FSharp.Core.FSharpFunc`2<Boolean[],Microsoft.FSharp.Core.Unit>>>)
   at Brahma.FSharp.OpenCL.WorkflowBuilder.Basic+RunCommand@33-1[[Brahma.OpenCL._1D, YC.Brahma.OpenCL, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(OpenCLEvaluationContext)
   at Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation+Bind@64[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(OpenCLEvaluationContext)
   at Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation+Bind@64[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(OpenCLEvaluationContext)
   at Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation+Bind@64[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(OpenCLEvaluationContext)
   at Brahma.FSharp.OpenCL.WorkflowBuilder.Basic.OpenCLEvaluationContext.RunSync[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](OpenCLEvaluationContext, OpenCLEvaluation`1<System.__Canon>)
   at Program.main(System.String[])
Segmentation fault

To Reproduce

module internal Utils =
    let defaultWorkGroupSize = 256

    let getDefaultGlobalSize n =
        let m = n - 1
        m - m % defaultWorkGroupSize + defaultWorkGroupSize

module internal rec Copy =
    let copyArray (inputArray: 'a[]) =
        if inputArray.Length = 0 then
            opencl { return [||] }
        else
            copyNonEmpty inputArray

    let private copyNonEmpty (inputArray: 'a[]) = opencl {
        let inputArrayLength = inputArray.Length
        let copy =
            <@
                fun (ndRange: _1D)
                    (inputArrayBuffer: 'a[])
                    (outputArrayBuffer: 'a[]) ->

                    let i = ndRange.GlobalID0
                    if i < inputArrayLength then
                        outputArrayBuffer.[i] <- inputArrayBuffer.[i]
            @>

        let outputArray = Array.zeroCreate inputArray.Length

        do! RunCommand copy <| fun kernelPrepare ->
            let ndRange = _1D(Utils.getDefaultGlobalSize inputArray.Length, Utils.defaultWorkGroupSize)
            kernelPrepare ndRange inputArray outputArray

        return outputArray
    }

[<EntryPoint>]
let main argv =
    opencl {
        let array = Array.create 100_000 true
        let! copied = Copy.copyArray array
        return array
    }
    |> OpenCLEvaluationContext().RunSync
    |> ignore

    0

Desktop (please complete the following information):

  • OS: Windows 7
  • Device: Intel CPU
  • Target: netcoreapp3.1; net461
  • Version: 2.0.0-alpha6.1
gsvgit added a commit that referenced this issue Oct 15, 2021
## [2.0.0-alpha9] - 2021-10-15

### Added
- Workflow builder for OpenCL computations

### Fixed
- Boolean type support (issue ##116, #116)
gsvgit added a commit that referenced this issue Jul 5, 2022
## [2.0.0] - 2022-07-05

### Fixed
- Blittable types transfer
- Performance issues
- Pointers to private variables are explicitly private
- Performance of blittable types
- Performance of kernels creation
- Issue #135
- Native opencl library linking
- Atomics
- ClArray memory management
- API for buffers manipulation
- Boolean type support (issue ##116, #116)
- Nested functions
- Complex let bindings
- ToHost behaviour on non-gpu arrays
- printf/printfn without arguments
- Boolean binary operators
- Transfer arrays of boolean
- Local memory semantic. It is forbidden to initialize variables in the local memory.

- Blittable types transfer
- Performance issues
- Pointers to private variables are explicitly private
- Performance of blittable types
- Performance of kernels creation
- Issue #135
- Native opencl library linking
- Atomics
- ClArray memory management
- API for buffers manipulation
- Boolean type support (issue ##116, #116)
- Nested functions
- Complex let bindings
- ToHost behaviour on non-gpu arrays
- printf/printfn without arguments
- Boolean binary operators
- Transfer arrays of boolean
- Local memory semantic. It is forbidden to initialize variables in the local memory.

### Added
- New abstraction for OpenCL device
- Getting workGroupSize inside kernels
- Discriminated unions inside kernel functions
- Stepped and non-integer loops
- ```ClCell``` support
- support of following types
  - ```Tuple``` and ```ValueTuple```
  - Records including generic records
- Workflow builder for OpenCL computations
- New mailbox processor based API
- Targeting .net 5.0
- Kernel compilation caching
- Mutable variables in closures
- support of printf call inside kernel code
- While and for loops in workflow builders
- Basic workflow builders for designing computations

- New abstraction for OpenCL device
- Getting workGroupSize inside kernels
- Discriminated unions inside kernel functions
- Stepped and non-integer loops
- ```ClCell``` support
- support of following types
  - ```Tuple``` and ```ValueTuple```
  - Records including generic records
- Workflow builder for OpenCL computations
- New mailbox processor based API
- Targeting .net 5.0
- Kernel compilation caching
- Mutable variables in closures
- support of printf call inside kernel code
- While and for loops in workflow builders
- Basic workflow builders for designing computations
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

Successfully merging a pull request may close this issue.

1 participant