我很难将 CL_HALF_FLOAT 类型的数据发送到 AMD HD 7990 GPU。
目前我正在使用 OpenEXR 读取 .exr 文件并将数据存储在名为“像素”的缓冲区中。
// 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;
}
我确信图像被正确读取,因为如果我使用内置 OpenEXR 函数使用“像素”写入文件,它会产生相同的输出图像。
创建缓冲区对象“inputImageBuffer”不会产生任何错误。
// Set Persistent memory only for AMD platform
cl_mem_flags inMemFlags = CL_MEM_READ_ONLY;
if (args->isAmdPlatform()){
inMemFlags |= CL_MEM_USE_PERSISTENT_MEM_AMD; // Faster transfer speed under windows 7
}
cl::Buffer inputImageBuffer;
// Create memory object for input image on the device
inputImageBuffer = cl::Buffer(
context, // Context
inMemFlags, // Flags
imageWidth * imageHeight * numChannels * sizeof(CL_HALF_FLOAT), // Size
NULL, // Host pointer
&status); // Status check
statusCheck(status, "Buffer::Buffer() failed. (inputImageBuffer)");
但是,当我尝试使用函数 enqueueWriteBuffer 发送数据时,程序崩溃并且没有返回有用的调试信息。
// Copy pixels to inputBufferImage
status = commandQueue.enqueueWriteBuffer(
inputImageBuffer,
CL_TRUE,
0,
imageWidth * imageHeight * numChannels * sizeof(CL_HALF_FLOAT),
&pixels);
statusCheck(status, "Copying failed");
我认为错误可能在于我如何声明每个缓冲区的大小,但我不确定,任何帮助将不胜感激。
谢谢