[Beignet] [PATCH opencl-1.2] Implement the clEnqueueMigrateMemObjects API

Zhigang Gong zhigang.gong at linux.intel.com
Wed Jun 11 00:51:07 PDT 2014


On Wed, Jun 11, 2014 at 01:18:02PM +0800, Zhigang Gong wrote:
> On Wed, Jun 11, 2014 at 09:33:36AM +0800, junyan.he at inbox.com wrote:
> > From: Junyan He <junyan.he at linux.intel.com>
> > 
> > So far, we just support 1 device and no subdevices.
> > So all the command queues should belong to the small context.
> > There is no need to migrate the mem objects from one subcontext
> > to another by now. We just do the checks and fill the event.
> Each new context should have its own bufmgr. And different bufmgr should
> not share at the buffer at the buffer object handle level. Instead,
> we need to export one buffer object's global name to another context
> and then create a new bo from that name in the target context's bufmgr
> domain.

I just got confused by the description of the clEnqueueMigrateMemObjects().
Read the spec carefuly again, and it turns out that it's only used to migrate memory
objects which belong to the same context but different devices. And those devices must
be subdevices of the same device. As we don't really support subdevice, we don't need
to do anything else in this API.

So this patch is ok for me, I will push it latter. Thanks.
> 
> > 
> > Signed-off-by: Junyan He <junyan.he at linux.intel.com>
> > ---
> >  src/cl_api.c     |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  src/cl_enqueue.c |    1 +
> >  src/cl_enqueue.h |    1 +
> >  3 files changed, 54 insertions(+)
> > 
> > diff --git a/src/cl_api.c b/src/cl_api.c
> > index 9747a0f..4ea7d6c 100644
> > --- a/src/cl_api.c
> > +++ b/src/cl_api.c
> > @@ -2564,6 +2564,58 @@ error:
> >  }
> >  
> >  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)
> > +{
> > +  /* So far, we just support 1 device and no subdevice. So all the command queues
> > +     belong to the small context. There is no need to migrate the mem objects by now. */
> > +  cl_int err = CL_SUCCESS;
> > +  cl_uint i = 0;
> > +  enqueue_data *data, defer_enqueue_data = { 0 };
> > +
> > +  if (!flags & CL_MIGRATE_MEM_OBJECT_HOST)
> > +    CHECK_QUEUE(command_queue);
> > +
> > +  if (num_mem_objects == 0 || mem_objects == NULL) {
> > +    err = CL_INVALID_VALUE;
> > +    goto error;
> > +  }
> > +
> > +  if (flags && flags & ~(CL_MIGRATE_MEM_OBJECT_HOST |
> > +                         CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED)) {
> > +    err = CL_INVALID_VALUE;
> > +    goto error;
> > +  }
> > +
> > +  for (i = 0; i < num_mem_objects; i++) {
> > +    CHECK_MEM(mem_objects[i]);
> > +    if (mem_objects[i]->ctx != command_queue->ctx) {
> > +      err = CL_INVALID_CONTEXT;
> > +      goto error;
> > +    }
> > +  }
> > +
> > +  /* really nothing to do, fill the event. */
> > +  TRY(cl_event_check_waitlist, num_events_in_wait_list, event_wait_list, event, command_queue->ctx);
> > +  data = &defer_enqueue_data;
> > +  data->type = EnqueueMigrateMemObj;
> > +
> > +  if(handle_events(command_queue, num_events_in_wait_list, event_wait_list,
> > +                   event, data, CL_COMMAND_READ_BUFFER) == CL_ENQUEUE_EXECUTE_IMM) {
> > +    err = cl_enqueue_handle(event ? *event : NULL, data);
> > +    if(event) cl_event_set_status(*event, CL_COMPLETE);
> > +  }
> > +
> > +error:
> > +  return err;
> > +}
> > +
> > +cl_int
> >  clEnqueueNDRangeKernel(cl_command_queue  command_queue,
> >                         cl_kernel         kernel,
> >                         cl_uint           work_dim,
> > diff --git a/src/cl_enqueue.c b/src/cl_enqueue.c
> > index 4ec26c0..ff6ec9e 100644
> > --- a/src/cl_enqueue.c
> > +++ b/src/cl_enqueue.c
> > @@ -426,6 +426,7 @@ cl_int cl_enqueue_handle(cl_event event, enqueue_data* data)
> >        return CL_SUCCESS;
> >      case EnqueueNativeKernel:
> >        return cl_enqueue_native_kernel(data);
> > +    case EnqueueMigrateMemObj:
> >      default:
> >        return CL_SUCCESS;
> >    }
> > diff --git a/src/cl_enqueue.h b/src/cl_enqueue.h
> > index 1960cc2..6527602 100644
> > --- a/src/cl_enqueue.h
> > +++ b/src/cl_enqueue.h
> > @@ -43,6 +43,7 @@ typedef enum {
> >    EnqueueMarker,
> >    EnqueueBarrier,
> >    EnqueueFillBuffer,
> > +  EnqueueMigrateMemObj,
> >    EnqueueInvalid
> >  } enqueue_type;
> >  
> > -- 
> > 1.7.9.5
> > 
> > 
> > 
> > _______________________________________________
> > Beignet mailing list
> > Beignet at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/beignet
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list