When I code with CUDA in ubuntu16.04. I was confronted with misaligned address error. I was confused with the reason and search on the internet, but no good results can help me.
one problem is as follows:
in foo.cu has a function:
void integration(unsigned char*a, unsigned short s, float d, float trans[]){
float m_depthIntegration;
uchar4 m_colorIntegration;
cudaSafeCall(cudaMalloc(&m_depthIntegration, sizeof(float)640480));//here is the misaligned address error
cudaSafeCall(cudaMalloc(&m_colorIntegration, sizeof(uchar4)640480));
cudaSafeCall(cudaMemcpy(m_depthIntegration, depth, sizeof(float)640480, cudaMemcpyHostToDevice));
cudaSafeCall(cudaMemcpy(m_colorIntegration, a2, sizeof(uchar4)640480, cudaMemcpyHostToDevice));
}
and i call this function in main.cpp but there is misaligned address error in this statement:cudaSafeCall(cudaMalloc(&m_depthIntegration, sizeof(float)640480));
the other one problem is as follow:
in CUDASceneRepHashSDF.h has a function:
unsigned int getHeapFreeCount() {
unsigned int count;
MLIB_CUDA_SAFE_CALL(cudaMemcpy(&count, m_hashData.d_heapCounter, sizeof(unsigned int), cudaMemcpyDeviceToHost));
return count+1; //there is one more free than the address suggests (0 would be also a valid address)
}
when I call this funtion, there is a misaligned address in this statement:MLIB_CUDA_SAFE_CALL(cudaMemcpy(&count, m_hashData.d_heapCounter, sizeof(unsigned int), cudaMemcpyDeviceToHost));
and m_hashData is a struct HashDataStruct in VoxelUtilHashSDF.h and just like:
struct HashDataStruct {
…
…
uint* d_heap; //heap that manages free memory
uint* d_heapCounter;//single element; used as an atomic counter(points to the next free block)
int* d_hashDecision; //
int* d_hashDecisionPrefix; //
HashEntry* d_hash; //hash that stores pointers to sdf blocks
HashEntry* d_hashCompactified; //same as before except that only valid pointers are there
int* d_hashCompactifiedCounter; //atomic counter to add compactified entries atomically
Voxel* d_SDFBlocks; //sub-blocks that contain 8x8x8 voxels (linearized); are allocated by heap
int* d_hashBucketMutex;
}
Could someone tell me how I can solve the misaligned address erroe in the above two progam?
thank you very much!