gpt4 book ai didi

multithreading - Gstreamer缓冲区与CUDA转换

转载 作者:行者123 更新时间:2023-12-03 13:20:30 25 4
gpt4 key购买 nike

我想使用cuda转换(尝试将红色 channel 设置为0)gstreamer缓冲区。有一段代码:

__global__ void transform( guint8 *data, int width ){
uint x = (blockIdx.x * blockDim.x) + threadIdx.x;
uint y = (blockIdx.y * blockDim.y) + threadIdx.y;
uint pixPos = (y * width + x) * 4;
data[pixPos + 2] = 0; // BGRA format
}

void simple_transform( guint8 *data, int width, int height ){
guint8 *d_data;
guint8 size = width * height * 4;

checkCudaErrors( cudaMalloc( (void**)&d_data, size ) );
// copy original buffer into device
checkCudaErrors( cudaMemcpy( d_data, data, size, cudaMemcpyHostToDevice ) );

dim3 threads = dim3(8, 8);
dim3 blocks = dim3(width / threads.x, height / threads.y);

// execute kernel
transform<<< blocks, threads >>>( d_data, width );

// move back converted data to original buffer
checkCudaErrors( cudaMemcpy( data, d_data, size, cudaMemcpyDeviceToHost ) );

cudaFree( d_data );
}

问题是视频显示没有任何变化。我想看蓝绿色的图片,但是看不到。我的错误在哪里?

最佳答案

您正在将图像的总大小分配给guint8类型的变量

guint8 size = width * height * 4;

最多只能容纳255个值。必须将大小分配给较大数据类型的变量(例如 size_t)。
size_t size = width * height * 4;

关于multithreading - Gstreamer缓冲区与CUDA转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17659703/

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