How to dynamically alloc constant memory?

I want to get some buffers in constant memory because it is cached therefore faster than global memory. But I didn’t see any examples in SDK, which use dynamic alloc (something like cudaMalloc).

Could some expert shed some light on this?

Thanks,
Yong

You can’t do this I think.

Guide says “shared and constant variables have implied static storage.”

I don’t know if this is what you mean by dynamic, but you can do variable constant memory after the program has launched on the host. Here is a work around I’m using for a satellite image smoother using multiple pictures over time. :yes:

Host code should look something like this

size_t storage[numElements+1];

storage[0] = 0;
storage[1] = array[0] + sizeof(int) * numOfSomeElements;
storage[2] = array[1] + etc etc

After that, use your cudaMemcpyToSymbol (ask if you want more clarification, but it’s well documented and strait forward). Normal malloc commands will work but won’t do anything (you’ll have garbage in your constant memory). Using cudaMemcpyToSymbol, you’ll have an unrolled offset based array with your storage array containing the offsets to the information you need. This means that you can set up variable sizes before launching the kernel… but there’s a catch.

If you want to dynamically do that while on the device you are out of luck. This can only be done on the host so it’s not really dynamic in that sense, sorry. :(
Not sure if that’s what you meant by dynamic, but maybe something here will help. Best of luck! :))