Question

Is there any way to allocate and copy a CUDA constant memory area in 2 dimensions? cudaMemcpyToSymnbol of __constant__ seems not an option.

Was it helpful?

Solution

The quasirandomGenerator example in the CUDA SDK (or Samples) shows a two dimensional table being allocated in constant memory with a corresponding cudaMemcpyToSymbol to populate the table in quasirandomGenerator_kernel.cuh

declaration of the 2D table:

static __constant__ unsigned int c_Table[QRNG_DIMENSIONS][QRNG_RESOLUTION];

cudaMemcpyToSymbol call:

//Table initialization routine
static void initTableGPU(unsigned int tableCPU[QRNG_DIMENSIONS][QRNG_RESOLUTION]){
    cutilSafeCall( cudaMemcpyToSymbol(
        c_Table,
        tableCPU,
        QRNG_DIMENSIONS * QRNG_RESOLUTION * sizeof(unsigned int)
    ) );
}

The table is being handled under the hood in a one dimensional fashion (as suggested by pQB), so I don't know if it's what the OP was looking for exactly. The example gets installed automatically when you install the CUDA SDK (or Samples as they are called in CUDA 5.0 RC toolkit) but you can find it separately on the web here. Select the appropriate download link on the right hand side to get an archive with the sample code. Then open the archive and look for the file quasirandomGenerator_kernel.cuh

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top