Enqueues a command to indicate which device a set of memory objects should be associated with.
cl_int clEnqueueMigrateMemObjects(cl_command_queue command_queue,
cl_uint num_mem_objects,
const cl_mem *mem_objects,
cl_mem_migration_flags flags,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
cl_event *event)command_queue-
A valid host command-queue. The specified set of memory objects in
mem_objectswill be migrated to the OpenCL device associated withcommand_queueor to the host if theCL_MIGRATE_MEM_OBJECT_HOSThas been specified. num_mem_objects-
The number of memory objects specified in
mem_objects. mem_objects-
A pointer to a list of memory objects.
flags-
A bit-field that is used to specify migration options. The table below describes the possible values for flags.
cl_mem_migration flags Description CL_MIGRATE_MEM_OBJECT_HOSTThis flag indicates that the specified set of memory objects are to be migrated to the host, regardless of the target command-queue.
CL_MIGRATE_MEM_OBJECT_- CONTENT_UNDEFINEDThis flag indicates that the contents of the set of memory objects are undefined after migration. The specified set of memory objects are migrated to the device associated with
command_queuewithout incurring the overhead of migrating their contents. event_wait_list, num_events_in_wait_list-
Specify events that need to complete before this particular command can be executed. If
event_wait_listis NULL, then this particular command does not wait on any event to complete. Ifevent_wait_listis NULL,num_events_in_wait_listmust be 0. Ifevent_wait_listis not NULL, the list of events pointed to byevent_wait_listmust be valid andnum_events_in_wait_listmust be greater than 0. The events specified inevent_wait_listact as synchronization points. The context associated with events inevent_wait_listandcommand_queuemust be the same. The memory associated withevent_wait_listcan be reused or freed after the function returns. event-
Returns an event object that identifies this particular command and can be used to query or queue a wait for this particular command to complete.
eventcan be NULL in which case it will not be possible for the application to query the status of this command or queue a wait for this command to complete. If theevent_wait_listand theeventarguments are not NULL, theeventargument should not refer to an element of theevent_wait_listarray.
This section describes 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:
-
Ensure that an object is allocated on a specific device prior to usage.
-
Preemptively migrate an object from one device to another.
Typically, memory objects are implicitly migrated to a device for which enqueued commands, using the memory object, are targeted.
clEnqueueMigrateMemObjects allows this migration to be explicitly performed ahead of the dependent commands.
This allows a user to preemptively change the association of a memory object, through regular command queue scheduling, in order to prepare for another upcoming command.
This also permits an application to overlap the placement of memory objects with other unrelated operations before these memory objects are needed potentially hiding transfer latencies.
Once the event, returned from clEnqueueMigrateMemObjects, has been marked CL_COMPLETE the memory objects specified in mem_objects have been successfully migrated to the device associated with command_queue.
The migrated memory object shall remain resident on the device until another command is enqueued that either implicitly or explicitly migrates it away.
clEnqueueMigrateMemObjects can also be used to direct the initial placement of a memory object, after creation, possibly avoiding the initial overhead of instantiating the object on the first enqueued command to use it.
The user is responsible for managing the event dependencies, associated with this command, in order to avoid overlapping access to memory objects.
Improperly specified event dependencies passed to clEnqueueMigrateMemObjects could result in undefined results.
clEnqueueMigrateMemObjects returns CL_SUCCESS if the function is executed successfully.
Otherwise, it returns one of the following errors:
-
CL_INVALID_COMMAND_QUEUEifcommand_queueis not a valid host command_queue. -
CL_INVALID_CONTEXTif the context associated withcommand_queueand memory objects inmemobjare not the same or if the context associated withcommand_queueand events inevent_wait_listare not the same. -
CL_INVALID_MEM_OBJECTif any of the memory objects inmem_objsis not a valid memory object. -
CL_INVALID_VALUEifnum_mem_objectsis zero or ifmem_objectsis NULL. -
CL_INVALID_VALUEifflagsis not 0 or is not any of the values described in the table above. -
CL_INVALID_EVENT_WAIT_LISTifevent_wait_listis NULL andnum_events_in_wait_list> 0, orevent_wait_listis not NULL andnum_events_in_wait_listis 0, or if event objects inevent_wait_listare not valid events. -
CL_MEM_OBJECT_ALLOCATION_FAILUREif there is a failure to allocate memory for the specified set of memory objects inmem_objects. -
CL_OUT_OF_RESOURCESif there is a failure to allocate resources required by the OpenCL implementation on the device. -
CL_OUT_OF_HOST_MEMORYif there is a failure to allocate resources required by the OpenCL implementation on the host.