Menu

#71 Nested functions on device

open
nobody
5
2011-02-18
2011-02-18
No

Allow using nested functions in device-side code. As OpenCL devices do not generally support recursion and function pointers, nested functions will be used only as nested functions, not full-blown closures. It would be possible to use variables defined in the outer function inside the nested function; however, the lifetime of those variables will be limited to the call of outer function.

As there is a more-or-less fixed order of parse tree processing for nested function, it is easier to have their code at call point. Therefore, nested functions would be easier than usual ones to inline and use in other transformations which require the function's entire code tree.

At the first time, full type declarations may be required for nested functions. Later on, those restrictions could be eased.

E.g.:

nuwork(64) nfor(i in n) {
def fa1(j : int) : float {
a[j + 1 + localShift]
};
...
def b = g(fa1(i), fa1(i-2), fa1(i-2));
...
}

Discussion

MongoDB Logo MongoDB