Constant memory for only one kernel multiple kernels in file, only want constant mem for one

I am working on a library of kernels. My main program runs each kernel a number of times so that it can measure their performance. I would like to use Constant Memory in some of them, but since Constant Memory has the lifetime of the application, I believe there will be interference between the different kernels.

One option would be to just create an array that uses all of the Constant Memory, and then over-write as much of it as I need with the desired data before each kernel that uses the Constant Memory. It’s messy (I’ll have to change the names of variables in the kernels to whatever I call the array - not good for readability, etc.), but it’s the only thing I can think of.

Any other ideas? Will having Constant Memory allocated, even though I’m not using it, affect the performance of the kernels that don’t use Constant Memory?

use union (or union array) with 64k to organize the constant memory, to improve the readability and easy to write code.

For example, one kernel need a float array, but another kernel need ushort4 array,

union UnionCM


float mFloat[64k / sizeof(float)];

ushort4 mUShort[64k/sizeof(ushort4)];


and fill UnionCM and copy it constant memory as your need.