skhan
November 15, 2010, 2:07am
1
Hi everyone,
I want to allocate memory on device for structure of 2D array. The structure and memory allocation code is as follows:
struct Cell
{
unsigned short** R;
unsigned short** G;
unsigned short** B;
unsigned short** Count;
};
Cell* BGM;
size_BGM = WidthHeight sizeof(unsigned short);
cudaMalloc((void **)((BGM->R)), 4sizeof(unsigned short ));
for (int j=0; j<4; j++) cudaMalloc((void **)(&(BGM->R[j])), size_BGM);
cudaMalloc((void **)((BGM->G)), 4sizeof(unsigned short ));
for (int j=0; j<4; j++) cudaMalloc((void **)(&(BGM->G[j])), size_BGM);
cudaMalloc((void **)((BGM->B)), 4sizeof(unsigned short ));
for (int j=0; j<4; j++) cudaMalloc((void **)(&(BGM->B[j])), size_BGM);
cudaMalloc((void **)((BGM->Count)), 4sizeof(unsigned short ));
for (int j=0; j<4; j++) cudaMalloc((void **)(&(BGM->Count[j])), size_BGM);
But when I pass pointer BGM to cuda kernel and access using BGM->R[i][j], it gives “Warning: Cannot tell what pointer points to, assuming global memory space”, and on execution gives segmentation fault.
Any help would be highly appreciated as I’ve got stuck with this.
skhan
November 15, 2010, 2:07am
2
Hi everyone,
I want to allocate memory on device for structure of 2D array. The structure and memory allocation code is as follows:
struct Cell
{
unsigned short** R;
unsigned short** G;
unsigned short** B;
unsigned short** Count;
};
Cell* BGM;
size_BGM = WidthHeight sizeof(unsigned short);
cudaMalloc((void **)((BGM->R)), 4sizeof(unsigned short ));
for (int j=0; j<4; j++) cudaMalloc((void **)(&(BGM->R[j])), size_BGM);
cudaMalloc((void **)((BGM->G)), 4sizeof(unsigned short ));
for (int j=0; j<4; j++) cudaMalloc((void **)(&(BGM->G[j])), size_BGM);
cudaMalloc((void **)((BGM->B)), 4sizeof(unsigned short ));
for (int j=0; j<4; j++) cudaMalloc((void **)(&(BGM->B[j])), size_BGM);
cudaMalloc((void **)((BGM->Count)), 4sizeof(unsigned short ));
for (int j=0; j<4; j++) cudaMalloc((void **)(&(BGM->Count[j])), size_BGM);
But when I pass pointer BGM to cuda kernel and access using BGM->R[i][j], it gives “Warning: Cannot tell what pointer points to, assuming global memory space”, and on execution gives segmentation fault.
Any help would be highly appreciated as I’ve got stuck with this.
avidday
November 15, 2010, 4:57am
3
Every pointer you supply to cudaMalloc() must be a pointer in host memory. Right now you are mixing host and device pointers all through that code.
avidday
November 15, 2010, 4:57am
4
Every pointer you supply to cudaMalloc() must be a pointer in host memory. Right now you are mixing host and device pointers all through that code.