using constant memory prints address instead of value in cuda

后端 未结 1 395
你的背包
你的背包 2021-01-29 11:39

I am trying to use the constant memory in the code with constant memory assigned value from kernel not using cudacopytosymbol.

 #include 
    usi         


        
相关标签:
1条回答
  • 2021-01-29 11:49

    Constant memory is, as the name implies, constant/read-only with respect to device code. What you are trying to do is illegal and can't be made to work.

    To set values in constant memory, you currently have two choices:

    1. set the value from host code via the cudaMemcpyToSymbol API call (or its equivalents)
    2. use static initialisation at compile time

    In the latter case something like this would work:

    __constant__ int constBuf[N] = { 16, 2, 77, 40, 12, 3, 5, 3, 6, 6 };
    
    __global__ void foo( int *results )
    {
        int tdx = threadIdx.x;
        int idx = blockIdx.x * blockDim.x + tdx;
    
    
        if( tdx < N )
        {
            results[idx] = constBuf[tdx]; // Note changes here!
        }
    }
    
    0 讨论(0)
提交回复
热议问题