I have a constant variable which is a
int*
.
I allocate and copy the value to this variable in a host function.
Cuda Memcheck reports access violations.
code:
__constant__ int *dev_gridx; // outside any functions in this .cu file
cudaError_t Renderer::renderWithCuda(double *T) {
// ...
cudaStatus = cudaMalloc((void**)&dev_gridx, sizeof(int));
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMalloc failed!");
}
cudaStatus = cudaMemcpyToSymbol(dev_gridx, &gridx, sizeof(int)); // gridx is a int* variable on cpu
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaMemcpy failed! gridx");
}
// ...
}
__global__ kernel() {
int x = blockIdx.x*blockDim.x + threadIdx.x;
int y = blockIdx.y*blockDim.y + threadIdx.y;
int z = blockIdx.z*blockDim.z + threadIdx.z;
/* 3D grid with 1D block:*/
int gridx = dev_gridx; // dev_gridx is stored in constant memory, reported access violation
}
error message:
================================================================================
CUDA Memory Checker detected 32 threads caused an access violation:
Launch Parameters
CUcontext = 00fcf578
CUstream = 043ec108
CUmodule = 078f64f0
CUfunction = 0bcb38e8
FunctionName = _Z14radianceKernelPdS_S_S_
GridId = 17
gridDim = {16,1,1}
blockDim = {89,1,1}
sharedSize = 256
Parameters:
dev_le = 0x08dd0000 0
dev_l = 0x08a21e00 0
dev_le_mean = 0x08a22200 0
dev_temperature_grid = 0x08cd0000 -6.27743856220419e+66
Parameters (raw):
0x08dd0000 0x08a21e00 0x08a22200 0x08cd0000
Summary of access violations:
path\kernel.cu(900): error MemoryChecker: #misaligned=32 #invalidAddress=0
================================================================================
Memory Checker detected 32 access violations.
error = misaligned load (global memory)
gridid = 17
blockIdx = {0,0,0}
threadIdx = {0,0,0}
address = 0x0000001e
accessSize = 4