OpenCL-将数据写入设备

OpenCL-将数据写入设备,opencl,gpgpu,openexr,Opencl,Gpgpu,Openexr,我在向AMD HD 7990 GPU发送CL_HALF_FLOAT类型的数据时遇到困难 目前,我正在使用OpenEXR读取一个.exr文件,并将数据存储在名为“pixels”的缓冲区中 // http://www.openexr.com/ReadingAndWritingImageFiles.pdf Imf::Array2D<Imf::Rgba> pixels; // Input image buffer try{ std::string fileName = resou

我在向AMD HD 7990 GPU发送CL_HALF_FLOAT类型的数据时遇到困难

目前,我正在使用OpenEXR读取一个.exr文件,并将数据存储在名为“pixels”的缓冲区中

// http://www.openexr.com/ReadingAndWritingImageFiles.pdf

Imf::Array2D<Imf::Rgba> pixels; // Input image buffer

try{
    std::string fileName = resourcesDirectory + "Input/tunnel/00000.exr"; // Read in test file
    std::cout << "Reading " << fileName << std::endl;
    Imf::RgbaInputFile file(fileName.c_str()); // Constructor opens the file and reads the files header - dataWindow
    Imath::Box2i dataWindow = file.dataWindow(); // File's data window
    imageWidth = dataWindow.max.x - dataWindow.min.x + 1; // Width of image
    imageHeight = dataWindow.max.y - dataWindow.min.y + 1; // Height of image
    pixels.resizeErase(imageHeight, imageWidth); // Performs allocation
    // Tell the RgbaInputFile object how to access individual pixels in the buffer
    file.setFrameBuffer(&pixels[0][0] - dataWindow.min.x - dataWindow.min.y * imageWidth, 1, imageWidth);
    // Copy the pixel data from the file into the buffer
    file.readPixels(dataWindow.min.y, dataWindow.max.y);
    // How many channels does the image have?
    switch (file.channels()){
        case Imf::WRITE_RGBA:
            numChannels = 4;
            break;
        case Imf::WRITE_RGB:
            numChannels = 3;
            break;
        default:
            throw std::runtime_error("Unable to load EXR files that are not RGBA or RGB");
    }
    std::cout << "Image has " << numChannels << " channels\n";
}catch (Iex::BaseExc & e){
    std::cout << e.what() << std::endl;
}
但是,当我尝试使用函数enqueueWriteBuffer发送数据时,程序崩溃,并且没有返回任何有用的调试信息

// Copy pixels to inputBufferImage
status = commandQueue.enqueueWriteBuffer(
    inputImageBuffer, 
    CL_TRUE, 
    0,
    imageWidth * imageHeight * numChannels * sizeof(CL_HALF_FLOAT),
    &pixels); 
statusCheck(status, "Copying failed");
我认为错误可能在于我如何声明每个缓冲区的大小,但我不确定,任何帮助都将不胜感激


谢谢

你的问题主要源于C++和对库制造商的过度抽象。Array2D不是OpenCL enqueueWriteBuffer需要的原始平面内存,它也不提供任何实际访问内存的清晰方式

您基本上是给它一个指向类实例的指针,它尝试从中读取,而不是从实际包含像素的_数据中读取。看看它是如何实现的


您需要访问保存像素的实际内存。您可以修改模板并对其进行更改,也可以尝试使用像素[0]。如果实现与我链接的页面相同,它可能会起作用。

OpenExr文档在这方面很糟糕,但我很确定问题在于&pixels:


所以我想这就是原始数据所在。

谢谢您的回复。在过去一个小时做了更多的研究之后,我开始研究OpenCL enqueueWriteBuffer是如何访问“像素”数据的。虽然我不知道到底出了什么问题,但我觉得这可能是问题所在,你的回答很有道理。我已经决定使用OpenCV而不是OpenEXR,现在它似乎工作得很好。虽然我以后可能会回去修改你链接的模板,再次感谢。我测试了你找到的模式,但不幸的是程序崩溃了,我想我会坚持使用OpenCV。谢谢你的回复。
// Copy pixels to inputBufferImage
status = commandQueue.enqueueWriteBuffer(
    inputImageBuffer, 
    CL_TRUE, 
    0,
    imageWidth * imageHeight * numChannels * sizeof(CL_HALF_FLOAT),
    &pixels); 
statusCheck(status, "Copying failed");
status = commandQueue.enqueueWriteBuffer( 
             inputImageBuffer, 
             CL_TRUE, 
             0,
             imageWidth * imageHeight * numChannels * sizeof(CL_HALF_FLOAT),
             &pixels // <---- error here!
         );
&pixels[0][0] - dataWindow.min.x - dataWindow.min.y * imageWidth