mardi 24 mars 2015

Higher order functions in AleaGPU C#

I am trying to code C# versions (in C# style) of the F# reduce functions found here:


http://ift.tt/1OwCG6d


More specific to my question, take this function for example:



let multiReduce (opExpr:Expr<'T -> 'T -> 'T>) numWarps =
let warpStride = WARP_SIZE + WARP_SIZE / 2 + 1
let sharedSize = numwarps * warpStride

<@ fun tid (x:'T) ->
// stuff
@>


I'm primarily an F# guy, and I'm not quite sure how I should go about coding functions like these in C#. For the C# version, the multiReduce function will be a class member. So if I wanted to do a more direct translation of the F# code, I would return a Func from my MultiReduce member.


The other option would be to "flatten" the multiReduce function, so that my C# member version would have two extra parameters. So...



public T MultiReduce(Func<T,T,T> op, int numWarps, int tid, T x)
{
// stuff
}


But I don't think this would work for AleaGPU coding in all cases because the quoted expression in the F# version is a device function. You need the nested function structure to be able to separate the assignment of certain variables from the actual invocation of the function.


Another way I see to do it would be to make a MultiReduce class and have the opExpr and numWarps as fields, then make the function in the quotation a class member.


So how are higher order functions like these generally implemented in AleaGPU-C#? I don't think it's good to return Func<..> everywhere since I don't see this done much in C# coding. Is AleaGPU a special case where this would be ok?


Aucun commentaire:

Enregistrer un commentaire