CUDA - Image Data Copy

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Jane_yuhui/article/details/81670507
    // 2D image
    unsigned short* pDeviceImageData;
    cudaMalloc(&pDeviceImageData, nImgHeight*nImgWidth*sizeof(unsigned short));

    cudaError_t cudaerror = cudaSuccess;
    cudaerror = cudaMemcpy(pDeviceImageData, pImageDate, nImgHeight*nImgWidth*sizeof(unsigned short), cudaMemcpyHostToDevice);
    if (cudaSuccess != cudaerror)
    {
        return -1;
    }

    // 3D image or amount of images 
    cudaPitchedPtr pDeviceImage;
    cudaExtent extent = make_cudaExtent(nImgWidth * sizeof(unsigned short), nImgHeight, 1);
    cudaError_t cudaerror = cudaSuccess;
    cudaerror = cudaMalloc3D(&pDeviceImage, extent);

    cudaerror = cudaMemcpy2D( pDeviceImage.ptr, pDeviceImage.pitch,
        pImageDate, nImgWidth*sizeof(unsigned short), nImgWidth*sizeof(float), nImgHeight, cudaMemcpyHostToDevice );
    if (cudaSuccess != cudaerror)
    {
        return -1;
    }


 

猜你喜欢

转载自blog.csdn.net/Jane_yuhui/article/details/81670507