Use dynamic shared memory allocation for two different vectors

前端 未结 1 1981
忘了有多久
忘了有多久 2021-01-11 12:12

In kernel function, I want two vectors of shared memory, both with size length (actually sizeof(float)*size).

Since it is not possible to a

相关标签:
1条回答
  • 2021-01-11 12:41

    The C Programming guide section on __shared__ includes examples where you allocate multiple arrays from dynamically allocated shared memory:

    extern __shared__ float array[];
    __device__ void func()      // __device__ or __global__ function
    {
        short* array0 = (short*)array; 
        float* array1 = (float*)&array0[128];
        int*   array2 =   (int*)&array1[64];
    }
    

    Since you're just getting a pointer to an element and making that a new array, I believe you could adapt that to use dynamic offsets instead of the static offsets they have in the example. They also note that the alignment has to be the same, which shouldn't be an issue in your case.

    0 讨论(0)
提交回复
热议问题