opencl中的缓冲区分配在哪里? [英] Where is the buffer allocated in opencl?

查看:274
本文介绍了opencl中的缓冲区分配在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用C ++绑定在OpenCL中创建一个内存缓冲区.这句话看起来像

I was trying to create a memory buffer in OpenCL with C++ binding. The sentence looks like

cl::Buffer buffer(context,CL_MEM_READ_ONLY,sizeof(float)*(100));

这句话使我感到困惑,因为它没有指定分配内存的设备.原则上,context包含所选平台上的所有设备,包括cpu和gpu.缓冲区是否放置在所有设备共享的公共区域中,这是真的吗?

This sentence confuses me because it doesn't specify which device the memory is allocated on. In principle context contains all devices, including cpu and gpu, on the chosen platform. Is it true that the buffer is put in a common region shared by all the devices?

推荐答案

规范未定义内存的位置.对于API用户,它是在上下文中".

The spec does not define where the memory is. For the API user, it is "in the context".

如果您只有一台设备,则可能(99.99%)将位于设备中. (在极少数情况下,如果设备暂时没有足够的内存,则可能在主机中)

If you have one device only, probably (99.99%) is going to be in the device. (In rare cases it may be in the host if the device does not have enough memory for the time being)

如果有许多不同的设备,它将在创建时就位于其中之一.但是,根据内核的启动情况,它可能会透明地移动到另一台设备.

In case of many different devices, it will be in one of them at the creation. But it may move transparently to another device depending on the kernel launches.

这就是为什么调用 clEnqueueMIgrateMemObjects的原因(仅适用于OpenCL 1.2). 它允许用户向API提示一些有关需要在哪里存储的提示,并提前准备副本.

This is the reason why the call clEnqueueMIgrateMemObjects (OpenCL 1.2 only) exists. It allows the user to tell some hints to the API about where the memory will be needed, and prepare the copy in advance.

这是其作用的定义:

clEnqueueMIgrateMemObjects提供了一种机制,用于分配OpenCL内存对象所在的设备.用户可能希望在创建时对其存储对象的位置有更明确的控制.这可以用来:

clEnqueueMIgrateMemObjects provides a mechanism for assigning which device an OpenCL memory object resides. A user may wish to have more explicit control over the location of their memory objects on creation. This could be used to:

  • 确保在使用对象之前已在特定设备上分配了对象.
  • 抢先将对象从一台设备迁移到另一台设备.

通常,内存对象被隐式迁移到使用该内存对象作为目标的入队命令的设备

Typically, memory objects are implicitly migrated to a device for which enqueued commands, using the memory object, are targeted

这篇关于opencl中的缓冲区分配在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆