[Beignet] [PATCH 2/3] add clCreateBufferFromLibva() api

Lu, Guanqun guanqun.lu at intel.com
Thu Sep 26 18:59:07 PDT 2013


thanks for your advice of the naming style. I'll stick to it in later patchsets.
Regarding the unit test, it might be a bit hacky to provide such a unit test in our library, because this new api needs a bo handle name. (i could just create a new buffer and use it as the stub for bo handle name.)

> -----Original Message-----
> From: Zhigang Gong [mailto:zhigang.gong at linux.intel.com]
> Sent: Thursday, September 26, 2013 10:36 AM
> To: Lu, Guanqun
> Cc: beignet at lists.freedesktop.org
> Subject: Re: [Beignet] [PATCH 2/3] add clCreateBufferFromLibva() api
> 
> This patch and the following patch is to introduce new API to cl lib.
> It's better to put it into include/CL/cl_intel.h, and the naming rule is to follow
> other non-standard API : clMapBufferIntel(cl_mem, cl_int*); clXXXIntel.
> 
> And it's better to provide at least one unit test to show the usage model of
> these new APIs.
> 
> On Mon, Sep 23, 2013 at 02:57:49PM +0800, Lu Guanqun wrote:
> > Signed-off-by: Lu Guanqun <guanqun.lu at intel.com>
> > ---
> >  include/CL/cl.h          |    5 +++++
> >  src/cl_api.c             |   17 +++++++++++++++++
> >  src/cl_driver.h          |    3 +++
> >  src/cl_driver_defs.c     |    1 +
> >  src/cl_mem.c             |   26 ++++++++++++++++++++++++++
> >  src/cl_mem.h             |    4 ++++
> >  src/intel/intel_driver.c |   15 +++++++++++++++
> >  7 files changed, 71 insertions(+)
> >
> > diff --git a/include/CL/cl.h b/include/CL/cl.h index 4355e74..e53c7ed
> > 100644
> > --- a/include/CL/cl.h
> > +++ b/include/CL/cl.h
> > @@ -548,6 +548,11 @@ clCreateBuffer(cl_context   /* context */,
> >                 cl_int *     /* errcode_ret */)
> CL_API_SUFFIX__VERSION_1_0;
> >
> >  extern CL_API_ENTRY cl_mem CL_API_CALL
> > +clCreateBufferFromLibva(cl_context      /* context */,
> > +                        unsigned int    /* bo_name */,
> > +                        cl_int *        /* errcode_ret */)
> CL_API_SUFFIX__VERSION_1_0;
> > +
> > +extern CL_API_ENTRY cl_mem CL_API_CALL
> >  clCreateSubBuffer(cl_mem                   /* buffer */,
> >                    cl_mem_flags             /* flags */,
> >                    cl_buffer_create_type    /* buffer_create_type */,
> > diff --git a/src/cl_api.c b/src/cl_api.c index c81f730..62f778e 100644
> > --- a/src/cl_api.c
> > +++ b/src/cl_api.c
> > @@ -2562,3 +2562,20 @@ clCreateProgramWithLLVMIntel(cl_context
> context,
> >                                       errcode_ret);  }
> >
> > +cl_mem
> > +clCreateBufferFromLibva(cl_context  context,
> > +                        unsigned int bo_name,
> > +                        cl_int *errorcode_ret) {
> > +  cl_mem mem = NULL;
> > +  cl_int err = CL_SUCCESS;
> > +  CHECK_CONTEXT (context);
> > +
> > +  mem = cl_mem_new_libva_buffer(context, bo_name, &err);
> > +
> > +error:
> > +  if (errorcode_ret)
> > +    *errorcode_ret = err;
> > +  return mem;
> > +}
> > +
> > diff --git a/src/cl_driver.h b/src/cl_driver.h index 100b38d..88dea58
> > 100644
> > --- a/src/cl_driver.h
> > +++ b/src/cl_driver.h
> > @@ -223,6 +223,9 @@ extern cl_buffer_alloc_from_texture_cb
> > *cl_buffer_alloc_from_texture;  typedef void
> > (cl_buffer_release_from_texture_cb)(cl_context, unsigned int, int,
> > unsigned int);  extern cl_buffer_release_from_texture_cb
> > *cl_buffer_release_from_texture;
> >
> > +typedef cl_buffer (cl_buffer_get_buffer_from_libva_cb)(cl_context
> > +ctx, unsigned int bo_name, size_t *sz); extern
> > +cl_buffer_get_buffer_from_libva_cb *cl_buffer_get_buffer_from_libva;
> > +
> >  /* Unref a buffer and destroy it if no more ref */  typedef int
> > (cl_buffer_unreference_cb)(cl_buffer);
> >  extern cl_buffer_unreference_cb *cl_buffer_unreference; diff --git
> > a/src/cl_driver_defs.c b/src/cl_driver_defs.c index ac4ff7a..f67697e
> > 100644
> > --- a/src/cl_driver_defs.c
> > +++ b/src/cl_driver_defs.c
> > @@ -45,6 +45,7 @@ LOCAL cl_buffer_pin_cb *cl_buffer_pin = NULL;
> LOCAL
> > cl_buffer_unpin_cb *cl_buffer_unpin = NULL;  LOCAL
> > cl_buffer_subdata_cb *cl_buffer_subdata = NULL;  LOCAL
> > cl_buffer_wait_rendering_cb *cl_buffer_wait_rendering = NULL;
> > +LOCAL cl_buffer_get_buffer_from_libva_cb
> > +*cl_buffer_get_buffer_from_libva = NULL;
> >
> >  /* cl_khr_gl_sharing */
> >  LOCAL cl_gl_acquire_texture_cb *cl_gl_acquire_texture = NULL; diff
> > --git a/src/cl_mem.c b/src/cl_mem.c index 769e1cb..473b8cc 100644
> > --- a/src/cl_mem.c
> > +++ b/src/cl_mem.c
> > @@ -1021,3 +1021,29 @@ cl_mem_unpin(cl_mem mem)
> >    cl_buffer_unpin(mem->bo);
> >    return CL_SUCCESS;
> >  }
> > +
> > +LOCAL cl_mem cl_mem_new_libva_buffer(cl_context ctx,
> > +                                     unsigned int bo_name,
> > +                                     cl_int* errcode) {
> > +  cl_int err = CL_SUCCESS;
> > +  cl_mem mem = NULL;
> > +
> > +  mem = cl_mem_allocate(CL_MEM_BUFFER_TYPE, ctx, 0, 0, CL_FALSE,
> > + &err);  if (mem == NULL || err != CL_SUCCESS)
> > +    goto error;
> > +
> > +  size_t sz = 0;
> > +  mem->bo = cl_buffer_get_buffer_from_libva(ctx, bo_name, &sz);
> > + mem->size = sz;
> > +
> > +exit:
> > +  if (errcode)
> > +    *errcode = err;
> > +  return mem;
> > +
> > +error:
> > +  cl_mem_delete(mem);
> > +  mem = NULL;
> > +  goto exit;
> > +}
> > diff --git a/src/cl_mem.h b/src/cl_mem.h index ca601f9..6fa40bc 100644
> > --- a/src/cl_mem.h
> > +++ b/src/cl_mem.h
> > @@ -244,5 +244,9 @@ cl_mem_copy_image_region(const size_t *origin,
> const size_t *region,
> >                           const void *src, size_t src_row_pitch, size_t
> src_slice_pitch,
> >                           const struct _cl_mem_image *image);
> >
> > +extern cl_mem cl_mem_new_libva_buffer(cl_context ctx,
> > +                                      unsigned int bo_name,
> > +                                      cl_int *errcode);
> > +
> >  #endif /* __CL_MEM_H__ */
> >
> > diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c index
> > cc33914..dc194fe 100644
> > --- a/src/intel/intel_driver.c
> > +++ b/src/intel/intel_driver.c
> > @@ -583,6 +583,20 @@ intel_release_buffer_from_texture(cl_context ctx,
> > unsigned int target,  }  #endif
> >
> > +cl_buffer intel_share_buffer_from_libva(cl_context ctx,
> > +                                        unsigned int bo_name,
> > +                                        size_t *sz) {
> > +  drm_intel_bo *intel_bo;
> > +
> > +  intel_bo = intel_driver_share_buffer((intel_driver_t *)ctx->drv,
> > + "shared from libva", bo_name);
> > +
> > +  if (sz)
> > +    *sz = intel_bo->size;
> > +
> > +  return (cl_buffer)intel_bo;
> > +}
> > +
> >  static int32_t get_intel_tiling(cl_int tiling, uint32_t
> > *intel_tiling)  {
> >    switch (tiling) {
> > @@ -630,6 +644,7 @@ intel_setup_callbacks(void)
> >    cl_buffer_release_from_texture = (cl_buffer_release_from_texture_cb *)
> intel_release_buffer_from_texture;
> >    intel_set_cl_gl_callbacks();
> >  #endif
> > +  cl_buffer_get_buffer_from_libva =
> > + (cl_buffer_get_buffer_from_libva_cb *)
> > + intel_share_buffer_from_libva;
> >    cl_buffer_reference = (cl_buffer_reference_cb *)
> drm_intel_bo_reference;
> >    cl_buffer_unreference = (cl_buffer_unreference_cb *)
> drm_intel_bo_unreference;
> >    cl_buffer_map = (cl_buffer_map_cb *) drm_intel_bo_map;
> >
> > _______________________________________________
> > Beignet mailing list
> > Beignet at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list