I am trying to use openCL with FSCL in F #, but I am getting some errors that I don’t understand
open FSCL.Compiler
open FSCL.Language
open FSCL.Runtime
open Microsoft.FSharp.Linq.RuntimeHelpers
open System.Runtime.InteropServices
[<StructLayout(LayoutKind.Sequential)>]
type gpu_point2 =
struct
val mutable x: float32
val mutable y: float32
new ( q ,w) = {x=q; y=w}
end
[<ReflectedDefinition>]
let PointSum(a:gpu_point2,b:gpu_point2) =
let sx =(a.x+b.x)
let sy =(a.y+b.y)
gpu_point2(sx,sy)
[<ReflectedDefinition;Kernel>]
let Modgpu(b:float32[], c:float32[],wi:WorkItemInfo) =
let gid = wi.GlobalID(0)
let arp = Array.zeroCreate<gpu_point2> b.Length
let newpoint = gpu_point2(b.[gid],c.[gid])
arp.[gid] <- newpoint
arp
[<ReflectedDefinition;Kernel>]
let ModSum(a:gpu_point2[],b:gpu_point2[],wi:WorkItemInfo) =
let gid = wi.GlobalID(0)
let cadd = Array.zeroCreate<gpu_point2> a.Length
let newsum = PointSum(a.[gid],b.[gid])
cadd.[gid] <- newsum
cadd
[<ReflectedDefinition;Kernel>]
let ModSum2(a:gpu_point2[],b:gpu_point2[],wi:WorkItemInfo) =
let gid = wi.GlobalID(0)
let cadd = Array.zeroCreate<gpu_point2> a.Length
let newsum = gpu_point2(a.[gid].x+b.[gid].x,a.[gid].y+b.[gid].y)
cadd.[gid] <- newsum
cadd
let ws = WorkSize(64L)
let arr_s1= <@ Modgpu([|0.f..63.f|],[|63.f..(-1.f)..0.f|],ws)@>.Run()
let arr_s2 = <@ Modgpu([|63.f..(-1.f)..0.f|],[|0.f..63.f|],ws)@>.Run()
With this code, when I try to use ModSum as
let rsum = <@ ModSum(arr_s1,arr_s2,ws)@>.Run()
doesn't work, but instead, when I use ModSum2, it works fine
let rsum = <@ ModSum2(arr_s1,arr_s2,ws)@>.Run()
The error I get when I first start up is FSCL.Compiler.CompilerException: an unrecognized construct in the core of the NewObject kernel (gpu_point2, sx, sy)
and if I run the fsi console again, say System.NullReferenceException: the object reference is not set Into an instance of an object.
The only thing I know is that the error is not related to using another function, since I can define a point product function that works.
[<ReflectedDefinition>]
let PointProd(a:gpu_point2,b:gpu_point2) =
let f = (a.x*b.x)
let s = (a.y*b.y)
f+s
, , PointSum, ? ?
Edit/Update:
, :
[<StructLayout(LayoutKind.Sequential)>]
type gpu_point_2 = {x:float32; y:float32}
, gpu_point_2 , , , .