Error(Segmentation fault) while using cudaHostAlloc ,Does parameter size require size?

inline bool cudaAllocMapped( void** cpuPtr, void** gpuPtr, size_t size )
{
	if( !cpuPtr || !gpuPtr || size == 0 )
		return false;

	//CUDA(cudaSetDeviceFlags(cudaDeviceMapHost));

	if( CUDA_FAILED(cudaHostAlloc(cpuPtr, size, cudaHostAllocMapped)) )
		return false;

	if( CUDA_FAILED(cudaHostGetDevicePointer(gpuPtr, *cpuPtr, 0)) )
		return false;

	memset(*cpuPtr, 0, size);
	printf("[cuda]  cudaAllocMapped %zu bytes, CPU %p GPU %p\n", size, *cpuPtr, *gpuPtr);
	return true;
}

in the project i want to get NV12 and malloc memory, 5125121.5 can success,2562561.5can success. but when i use 3003001.5 which for SSD network, Segmentation fault arise on cudaHostAlloc

Your code works fine for me. My guess would be that the way you are calling it (the variables you are passing) is the problem. If you are passing a bare ** pointer, that won’t work, because it has no allocation for the thing it is pointing to.

$ cat t481.cu
#define CUDA_FAILED(x) x
#include <stdio.h>

inline bool cudaAllocMapped( void** cpuPtr, void** gpuPtr, size_t size )
{
        if( !cpuPtr || !gpuPtr || size == 0 )
                return false;

        //CUDA(cudaSetDeviceFlags(cudaDeviceMapHost));

        if( CUDA_FAILED(cudaHostAlloc(cpuPtr, size, cudaHostAllocMapped)) )
                return false;

        if( CUDA_FAILED(cudaHostGetDevicePointer(gpuPtr, *cpuPtr, 0)) )
                return false;

        memset(*cpuPtr, 0, size);
        printf("[cuda]  cudaAllocMapped %zu bytes, CPU %p GPU %p\n", size, *cpuPtr, *gpuPtr);
        return true;
}
int main(){

  float *data, *d_data;
  const size_t sz = 1000;
  cudaAllocMapped((void**)&data, (void**)&d_data, sz);
  return 0;
}
$ nvcc -o t481 t481.cu
$ cuda-memcheck ./t481
========= CUDA-MEMCHECK
[cuda]  cudaAllocMapped 1000 bytes, CPU 0x200c00000 GPU 0x200c00000
========= ERROR SUMMARY: 0 errors
$