gpt4 book ai didi

c++ - 调用函数时 CUDA/GPU 中的异常错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:46:31 27 4
gpt4 key购买 nike

您好,我在 CUDA 中遇到异常错误。我正在尝试按原样运行以下代码。

CUdeviceptr  pDecodedFrame[2] = { 0, 0 };
CUdeviceptr pInteropFrame[2] = { 0, 0 };

uint32 n_Width = g_pVideoDecoder->targetWidth();
uint32 n_Height = g_pVideoDecoder->targetHeight();

dim3 block(32,16,1);
dim3 grid((nWidth+(2*block.x-1))/(2*block.x), (nHeight+(block.y-1))/block.y, 1);

NV12ToARGB_drvapi<<<block,grid>>>(&pDecodedFrame[active_field], nDecodedPitch,
&pInteropFrame[active_field], nTexturePitch, nWidth, nHeight,constHueColorSpaceMat, constAlpha);

我的其他功能如下:

__global__ void NV12ToARGB_drvapi(uint32 *srcImage,     size_t nSourcePitch,
uint32 *dstImage, size_t nDestPitch,
uint32 width, uint32 height, float constHueColorSpaceMat[9] , uint32 constAlpha)
{
int32 x, y;
uint32 yuv101010Pel[2];
uint32 processingPitch = ((width) + 63) & ~63;
uint32 dstImagePitch = nDestPitch >> 2;
uint8 *srcImageU8 = (uint8 *)srcImage;

processingPitch = nSourcePitch;

// Pad borders with duplicate pixels, and we multiply by 2 because we process 2 pixels per thread
x = blockIdx.x * (blockDim.x << 1) + (threadIdx.x << 1);
y = blockIdx.y * blockDim.y + threadIdx.y;

if (x >= width)
return; //x = width - 1;

if (y >= height)
return; // y = height - 1;

// Read 2 Luma components at a time, so we don't waste processing since CbCr are decimated this way.
// if we move to texture we could read 4 luminance values
yuv101010Pel[0] = (srcImageU8[y * processingPitch + x ]) << 2;
yuv101010Pel[1] = (srcImageU8[y * processingPitch + x + 1]) << 2;

uint32 chromaOffset = processingPitch * height;
int32 y_chroma = y >> 1;

if (y & 1) // odd scanline ?
{
uint32 chromaCb;
uint32 chromaCr;

chromaCb = srcImageU8[chromaOffset + y_chroma * processingPitch + x ];
chromaCr = srcImageU8[chromaOffset + y_chroma * processingPitch + x + 1];

if (y_chroma < ((height >> 1) - 1)) // interpolate chroma vertically
{
chromaCb = (chromaCb + srcImageU8[chromaOffset + (y_chroma + 1) * processingPitch + x ] + 1) >> 1;
chromaCr = (chromaCr + srcImageU8[chromaOffset + (y_chroma + 1) * processingPitch + x + 1] + 1) >> 1;
}

yuv101010Pel[0] |= (chromaCb << (COLOR_COMPONENT_BIT_SIZE + 2));
yuv101010Pel[0] |= (chromaCr << ((COLOR_COMPONENT_BIT_SIZE << 1) + 2));

yuv101010Pel[1] |= (chromaCb << (COLOR_COMPONENT_BIT_SIZE + 2));
yuv101010Pel[1] |= (chromaCr << ((COLOR_COMPONENT_BIT_SIZE << 1) + 2));
}
else
{
yuv101010Pel[0] |= ((uint32)srcImageU8[chromaOffset + y_chroma * processingPitch + x ] << (COLOR_COMPONENT_BIT_SIZE + 2));
yuv101010Pel[0] |= ((uint32)srcImageU8[chromaOffset + y_chroma * processingPitch + x + 1] << ((COLOR_COMPONENT_BIT_SIZE << 1) + 2));

yuv101010Pel[1] |= ((uint32)srcImageU8[chromaOffset + y_chroma * processingPitch + x ] << (COLOR_COMPONENT_BIT_SIZE + 2));
yuv101010Pel[1] |= ((uint32)srcImageU8[chromaOffset + y_chroma * processingPitch + x + 1] << ((COLOR_COMPONENT_BIT_SIZE << 1) + 2));
}

// this steps performs the color conversion
uint32 yuvi[6];
float red[2], green[2], blue[2];

yuvi[0] = (yuv101010Pel[0] & COLOR_COMPONENT_MASK);
yuvi[1] = ((yuv101010Pel[0] >> COLOR_COMPONENT_BIT_SIZE) & COLOR_COMPONENT_MASK);
yuvi[2] = ((yuv101010Pel[0] >> (COLOR_COMPONENT_BIT_SIZE << 1)) & COLOR_COMPONENT_MASK);

yuvi[3] = (yuv101010Pel[1] & COLOR_COMPONENT_MASK);
yuvi[4] = ((yuv101010Pel[1] >> COLOR_COMPONENT_BIT_SIZE) & COLOR_COMPONENT_MASK);
yuvi[5] = ((yuv101010Pel[1] >> (COLOR_COMPONENT_BIT_SIZE << 1)) & COLOR_COMPONENT_MASK);

// YUV to RGB Transformation conversion
YUV2RGB(&yuvi[0], &red[0], &green[0], &blue[0], constHueColorSpaceMat);
YUV2RGB(&yuvi[3], &red[1], &green[1], &blue[1], constHueColorSpaceMat);

// Clamp the results to RGBA
dstImage[y * dstImagePitch + x ] = RGBAPACK_10bit(red[0], green[0], blue[0], constAlpha);
dstImage[y * dstImagePitch + x + 1 ] = RGBAPACK_10bit(red[1], green[1], blue[1], constAlpha);

}






__device__ void YUV2RGB(uint32 *yuvi, float *red, float *green, float *blue, float constHueColorSpaceMat[9])

{
float luma, chromaCb, chromaCr;

// Prepare for hue adjustment
luma = (float)yuvi[0];
chromaCb = (float)((int32)yuvi[1] - 512.0f);
chromaCr = (float)((int32)yuvi[2] - 512.0f);

// Convert YUV To RGB with hue adjustment
*red = MUL(luma, constHueColorSpaceMat[0]) +
MUL(chromaCb, constHueColorSpaceMat[1]) +
MUL(chromaCr, constHueColorSpaceMat[2]);
*green= MUL(luma, constHueColorSpaceMat[3]) +
MUL(chromaCb, constHueColorSpaceMat[4]) +
MUL(chromaCr, constHueColorSpaceMat[5]);
*blue = MUL(luma, constHueColorSpaceMat[6]) +
MUL(chromaCb, constHueColorSpaceMat[7]) +
MUL(chromaCr, constHueColorSpaceMat[8]);
}


__device__ uint32 RGBAPACK_8bit(float red, float green, float blue, uint32 alpha)
{
uint32 ARGBpixel = 0;

// Clamp final 10 bit results
red = min(max(red, 0.0f), 255.0f);
green = min(max(green, 0.0f), 255.0f);
blue = min(max(blue, 0.0f), 255.0f);

// Convert to 8 bit unsigned integers per color component
ARGBpixel = (((uint32)blue) |
(((uint32)green) << 8) |
(((uint32)red) << 16) | (uint32)alpha);

return ARGBpixel;
}

这是我遇到的错误

    First-chance exception at 0x7571812f in testing_project.exe: Microsoft C++ exception: cudaError at memory location 0x0015e6b8..
First-chance exception at 0x7571812f in testing_project.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..

每次我运行 GPU 代码时。任何人都可以在这里帮助我。

最佳答案

如果您的应用程序正常运行并且没有返回任何错误(您在做 proper cuda error checking 吗?),只有在 MSVC 环境中运行时才会看到第一次机会异常,并且可以安全地忽略。

一些 CUDA 库在普通处理函数期间会遇到异常。这些异常是正常处理的,但是当您处于 MSVC 环境中时,Visual Studio 会为您提供拦截异常并“第一次机会”访问它的选项,然后再将其传递给代码/库中内置的普通异常处理程序.

如果您在 MSVC 环境之外从命令行运行您的应用程序,则不应看到此内容。

如果切换到 CUDA 5.5,您可能还会看到行为上的差异

关于c++ - 调用函数时 CUDA/GPU 中的异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19682921/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com