2011-12-22 6 views
1

のWindows 7 AMDのApp SDK 2.6 ASICは値エラーの内容を確認します。のOpenCL image2d_tは

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); 
} 

カーネルは、だから私はREDに入力された画像をクリアしていますし、その後カーネルはちょうど出力に赤色を書き戻す必要があります。この

__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); 
} 

のように見えます。しかし、出力のすべてに対して0.0fを書き出すだけです。 clOutputImageの値が表示されない理由は何ですか?

答えて

1

この行が問題でした。
status = queue->enqueueNDRangeKernel(*kernel, 2, globalSize, cl::NullRange);

私は間違ってC引数リストを想定し、2を次元として追加しました。 2を削除すると問題が解決しました。