本文介绍了opencl image2d_t不写回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 7AMD App SDK 2.6Asic:红木

Windows 7AMD App SDK 2.6Asic: Redwood

我正在尝试编写一个简单的pass-thru内核,以查看问题所在,而我似乎找不到可能的错误.

I am trying to write a simple pass-thru kernel to see what the issue is and I can't seem to find what the error might be.

void kernel_test(CLManager* clMgr, int W, int H)
{
    cl::ImageFormat format;
    format.image_channel_order = CL_RGBA;
    format.image_channel_data_type = CL_FLOAT;

    cl_float4* inp = new cl_float4[W * H];

    for (int i = 0; i < W * H; ++i)
    {
        inp[i].s[0] = 1.0f;
        inp[i].s[1] = 0.0f;
        inp[i].s[2] = 0.0f;
        inp[i].s[3] = 1.0f;
    }

    cl_float4* oup = new cl_float4[W * H];

    cl::Image2D clInputImage  = clMgr->createImage<cl::Image2D>(CL_MEM_READ_ONLY, format, W, H, 0, NULL);
    cl::Image2D clOutputImage = clMgr->createImage<cl::Image2D>(CL_MEM_WRITE_ONLY, format, W, H, 0, NULL);
    cl::Sampler sampler = clMgr->createSampler(CL_FALSE, CL_ADDRESS_CLAMP_TO_EDGE, CL_FILTER_NEAREST);

    cl::size_t<3> origin;
    origin[0] = 0; origin[1] = 0, origin[2] = 0;
    cl::size_t<3> region;
    region[0] = W; region[1] = H; region[2] = 1;

    unsigned int pgmID = clMgr->buildSource("CL/convolution.cl");

    cl::Kernel* kernel = clMgr->makeKernel(pgmID, "passthru");

    cl::CommandQueue* queue = clMgr->getCmdQueue();

    queue->enqueueWriteImage(clInputImage, CL_TRUE, origin, region, 0, 0, inp, 0, NULL);

    int status;

    status = kernel->setArg(0, clInputImage);
    status = kernel->setArg(1, clOutputImage);
    status = kernel->setArg(2, sampler);

    cl::NDRange globalSize(W, H);

    std::cout << "Starting Kernel: passthru" << std::endl;

    status = queue->enqueueNDRangeKernel(*kernel, 2, globalSize, cl::NullRange);

    std::cout << "Ending Kernel: passthru" << std::endl;

    status = queue->enqueueReadImage(clOutputImage, CL_TRUE, origin, region, 0, 0, oup);
}

内核看起来像这样

__kernel
void passthru(__read_only image2d_t sourceImage,
                 __write_only image2d_t outputImage,
                 sampler_t sampler)
{
    // Store each work-items unique row and column
    int2 coords = (int2){get_global_id(0), get_global_id(1)};
    float4 pixel = read_imagef(sourceImage, sampler, coords);
    write_imagef(outputImage, coords, pixel);
}

因此,我将输入图像清除为RED,然后内核应将RED颜色写回输出.但是,它只为输出中的所有内容写出0.0f.为什么没有在clOutputImage中看到值的任何特定原因?

So I am clearing the input image to RED and then the kernel should just write back the RED color to the output. However, it just writes out 0.0f for everything in output. Any particular reason why I am not seeing the values in the clOutputImage?

推荐答案

问题出在这一行.
status = queue->enqueueNDRangeKernel(*kernel, 2, globalSize, cl::NullRange);

The problem was this line.
status = queue->enqueueNDRangeKernel(*kernel, 2, globalSize, cl::NullRange);

我被错误地假定为C参数列表,并添加了2作为维.删除2解决了问题.

I was mistakenly assumed the C argument list and added 2 as dimensions. Removing the 2 solved the problem.

这篇关于opencl image2d_t不写回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 19:08