Specifying multiple address spaces for a type in the list of arguments of function

时间:2016-02-03 03:13:03

标签: opencl

I wrote a function in OpenCL:

void sort(int* array, int size)
{
}

and I need to call the function once over a __private array and once over a __global array. Apparently, it's not allowed in OpenCL to specify multiple address spaces for a type. Therefore, I should duplicate the declaration of function, while they have exactly the same body:

void sort_g(__global int* array, int size)
{
}

void sort_p(__private int* array, int size)
{
}

This is very inefficient for maintaining the code and I am wondering if there is a better way to manage multiple address spaces in OpenCL or not?

P.S.: I don't see why OpenCL doesn't allow multiple address spaces for a type. Compiler could generate multiple instances of the function (one per address space) and use them appropriately once they're called in the kernel.

1 个答案:

答案 0 :(得分:2)

  • 对于OpenCL< 2.0,这就是语言的设计方式,遗憾的是没有绕过它。

  • 对于OpenCL> = 2.0,通过引入通用地址空间,您的第一段代码可以正常运行。

简而言之,升级到2.0可以解决您的问题(并引入其他细节),否则您将失去运气(您可以将您的功能包装在一个宏中,但是,还可以将宏包裹起来)。