f# - FSCL error on a simple example -


i trying use opencl fscl on f# obtaining errors 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 code when try use modsum as

let rsum = <@ modsum(arr_s1,arr_s2,ws)@>.run() 

doesn't work, instead when use modsum2 works perfectly

let rsum = <@ modsum2(arr_s1,arr_s2,ws)@>.run() 

the error obtain first time run is
fscl.compiler.compilerexception: unrecognized construct in kernel body newobject (gpu_point2, sx, sy)
, if re-run fsi console says
system.nullreferenceexception: object reference not set instance of object.

the thing know error doesn't comes use of function since can define dot product function works.

[<reflecteddefinition>] let pointprod(a:gpu_point2,b:gpu_point2) =      let f = (a.x*b.x)     let s = (a.y*b.y)     f+s  

thus, guess problem comes return type of pointsum, there way create such function sum 2 points , return point type? , why not working?

edit/update:
record happens same if define type :

[<structlayout(layoutkind.sequential)>] type gpu_point_2 = {x:float32; y:float32}  

if try create function directly sums 2 gpu_point_2 on function works, if call second function raises same error using struct.

try add [<reflecteddefinition>] on constructor of gpu_point2:

[<structlayout(layoutkind.sequential)>] type gpu_point2 =     struct         val mutable x: float32         val mutable y: float32         [<reflecteddefinition>] new (q, w) = {x=q; y=w}      end   

normally each code called device need attribute, constructors included.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -