Created
November 28, 2016 16:25
-
-
Save josesoyo/3f2df25e418b8310056b18e5896867b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[<ConstantDefine>] | |
let pi = | |
3.1415926f | |
// define functions: | |
// FSCL function | |
[<ReflectedDefinition;Kernel>] | |
let DoStuffOpenCL (a1:float32[]) (a2:float32[]) (b:float32[]) (c:float32[]) (iters:float32[]) (wi:WorkItemInfo) = | |
// a1 and a2 are the same length | |
// b, c and iters are the same length and always lower than the length of a1&a2 | |
let gid = wi.GlobalID(0) | |
let outArr = Array.zeroCreate<float32> a1.Length | |
let mutable acc = a1.[gid] | |
for i in 0..iters.Length-1 do | |
acc <- b.[i]*cos(pi*iters.[i]*a2.[gid]+c.[i])+acc | |
outArr.[gid] <- acc | |
outArr | |
// Fsharp function | |
let DoStuff (a:float32, b:float32[], c:float32[], iters:float32[]) = | |
// function to compute the globlal modulation (sum of all) | |
Array.fold(fun acc x -> acc+b.[x]*cos(pi*iters.[x]*a+c.[x]) ) 0.f [|0..iters.Length-1|] // value*b.[i]*cos(pi*iters.[i]*a2.[gid]+c.[i])+acc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment