简体   繁体   中英

OpenCL - Work item specific local memory?

Lets assume for a moment that the private scope is littered with variables that cannot be removed and adding additional private variables will cause register spilling. However, we still need a few more scratch variables so we decide to allocate them in local memory. We know in advance 1) how much local memory is available and 2) the constant work group size.

Is there a way to declare a work item ( not work group) specific local memory object?
The work item will not be sharing the results with other work items, it simply needs it for itself.

The only way I can currently think of involves something ugly like:

local uint dataLump[WORK_GROUP_SIZE];
local uint* myTempVar = &dataLump[get_local_id(0)];

Is there a better way?

The compiler should be clever enough to use local memory if it has to spill private registers, rather than global memory.

But in case that does not happen (and I don't trust driver developers), you can do it this way:

#define L_MEM(x) x[get_local_id(0)]

local uint lvar1[WORK_GROUP_SIZE]; //Declare

//Access
uint a = b + L_MEM(lvar1);

Notice I don't use a pointer, since that will be shared across the group, and overwriteen by all the WI. You have to do a direct access with the WI_id. The macro option is a good help there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM