本文整理汇总了C++中DeviceInterface::createDeviceBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ DeviceInterface::createDeviceBuffer方法的具体用法?C++ DeviceInterface::createDeviceBuffer怎么用?C++ DeviceInterface::createDeviceBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeviceInterface
的用法示例。
在下文中一共展示了DeviceInterface::createDeviceBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
cl_int MemObject::init()
{
// Get the device list of the context
DeviceInterface **devices = 0;
cl_int rs;
rs = context()->info(CL_CONTEXT_NUM_DEVICES, sizeof(uint), &p_num_devices, 0);
if (rs != CL_SUCCESS)
return rs;
devices = (DeviceInterface **)malloc(p_num_devices *
sizeof(DeviceInterface *));
if (!devices)
return CL_OUT_OF_HOST_MEMORY;
rs = context()->info(CL_CONTEXT_DEVICES,
p_num_devices * sizeof(DeviceInterface *), devices, 0);
if (rs != CL_SUCCESS)
return rs;
// Allocate a table of DeviceBuffers
p_devicebuffers = (DeviceBuffer **)malloc(p_num_devices *
sizeof(DeviceBuffer *));
if (!p_devicebuffers)
return CL_OUT_OF_HOST_MEMORY;
// Create a DeviceBuffer for each device
for (int i=0; i<p_num_devices; ++i)
{
DeviceInterface *device = devices[i];
p_devicebuffers[i] = device->createDeviceBuffer(this, &rs);
if (rs != CL_SUCCESS)
{
free((void *)devices);
return rs;
}
}
// If we have only one device, already allocate the buffer
if (p_num_devices == 1)
{
rs = p_devicebuffers[0]->allocate();
if (rs != CL_SUCCESS)
return rs;
}
return CL_SUCCESS;
}
示例2: init
cl_int MemObject::init()
{
// Get the device list of the context
DeviceInterface **devices = 0;
cl_int rs;
rs = ((Context *)parent())->info(CL_CONTEXT_NUM_DEVICES,
sizeof(unsigned int),
&p_num_devices, 0);
if (rs != CL_SUCCESS)
return rs;
p_devices_to_allocate = p_num_devices;
devices = (DeviceInterface **)std::malloc(p_num_devices *
sizeof(DeviceInterface *));
if (!devices)
return CL_OUT_OF_HOST_MEMORY;
rs = ((Context *)parent())->info(CL_CONTEXT_DEVICES,
p_num_devices * sizeof(DeviceInterface *),
devices, 0);
if (rs != CL_SUCCESS)
{
std::free((void *)devices);
return rs;
}
// Allocate a table of DeviceBuffers
p_devicebuffers = (DeviceBuffer **)std::malloc(p_num_devices *
sizeof(DeviceBuffer *));
if (!p_devicebuffers)
{
std::free((void *)devices);
return CL_OUT_OF_HOST_MEMORY;
}
// If we have more than one device, the allocation on the devices is
// defered to first use, so host_ptr can become invalid. So, copy it in
// a RAM location and keep it. Also, set a flag telling CPU devices that
// they don't need to reallocate and re-copy host_ptr
if (p_num_devices > 1 && (p_flags & CL_MEM_COPY_HOST_PTR))
{
void *tmp_hostptr = std::malloc(size());
if (!tmp_hostptr)
{
std::free((void *)devices);
return CL_OUT_OF_HOST_MEMORY;
}
std::memcpy(tmp_hostptr, p_host_ptr, size());
p_host_ptr = tmp_hostptr;
// Now, the client application can safely std::free() its host_ptr
}
// Create a DeviceBuffer for each device
unsigned int failed_devices = 0;
for (unsigned int i=0; i<p_num_devices; ++i)
{
DeviceInterface *device = devices[i];
rs = CL_SUCCESS;
p_devicebuffers[i] = device->createDeviceBuffer(this, &rs);
if (rs != CL_SUCCESS)
{
p_devicebuffers[i] = 0;
failed_devices++;
}
}
if (failed_devices == p_num_devices)
{
// Each device found a reason to reject the buffer, so it's invalid
std::free((void *)devices);
return rs;
}
std::free((void *)devices);
devices = 0;
// If we have only one device, already allocate the buffer
if (p_num_devices == 1)
{
if (!p_devicebuffers[0]->allocate())
return CL_MEM_OBJECT_ALLOCATION_FAILURE;
}
return CL_SUCCESS;
}