[Mesa-dev] [PATCH 2/3] clover: Check allocation size against context maximum

Francisco Jerez currojerez at riseup.net
Sun Dec 15 23:55:14 PST 2013


Jan Vesely <jan.vesely at rutgers.edu> writes:

> From: Jan Vesely <jan.vesely at cs.rutgers.edu>
>
> Check maximum size across all devices in the context
>
> Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> ---
>  src/gallium/state_trackers/clover/api/memory.cpp   |  2 +-
>  src/gallium/state_trackers/clover/core/context.cpp | 11 +++++++++++
>  src/gallium/state_trackers/clover/core/context.hpp |  2 ++
>  3 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/src/gallium/state_trackers/clover/api/memory.cpp b/src/gallium/state_trackers/clover/api/memory.cpp
> index 15f5b7f..b5b75cd 100644
> --- a/src/gallium/state_trackers/clover/api/memory.cpp
> +++ b/src/gallium/state_trackers/clover/api/memory.cpp
> @@ -35,7 +35,7 @@ clCreateBuffer(cl_context d_ctx, cl_mem_flags flags, size_t size,
>                                         CL_MEM_COPY_HOST_PTR)))
>        throw error(CL_INVALID_HOST_PTR);
>  
> -   if (!size)
> +   if (!size || size > ctx.max_mem_alloc_size())
>        throw error(CL_INVALID_BUFFER_SIZE);
>  

Can you avoid defining a new single-use method for this and do the
calculation right here instead?  Like:

|   if (!size ||
|       size > fold(maximum(), 0u,
|                   map(std::mem_fn(&device::max_mem_alloc_size), ctx.devs())
|          ))
|      throw error(CL_INVALID_BUFFER_SIZE);

With that fixed, Reviewed-by: Francisco Jerez <currojerez at riseup.net>

>     if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
> diff --git a/src/gallium/state_trackers/clover/core/context.cpp b/src/gallium/state_trackers/clover/core/context.cpp
> index e2658f2..d00c5b5 100644
> --- a/src/gallium/state_trackers/clover/core/context.cpp
> +++ b/src/gallium/state_trackers/clover/core/context.cpp
> @@ -48,3 +48,14 @@ context::device_range
>  context::devs() const {
>     return map(derefs(), _devs);
>  }
> +
> +static bool max_alloc_comp(const clover::device *a, const clover::device *b)
> +{
> +   return a->max_mem_alloc_size() < b->max_mem_alloc_size();
> +}
> +
> +cl_ulong context::max_mem_alloc_size() const {
> +   const clover::device *dev =
> +      *(std::max_element(_devs.begin(), _devs.end(), max_alloc_comp));
> +   return dev->max_mem_alloc_size();
> +}
> diff --git a/src/gallium/state_trackers/clover/core/context.hpp b/src/gallium/state_trackers/clover/core/context.hpp
> index 0b5cf8a..0bb5953 100644
> --- a/src/gallium/state_trackers/clover/core/context.hpp
> +++ b/src/gallium/state_trackers/clover/core/context.hpp
> @@ -50,6 +50,8 @@ namespace clover {
>  
>        device_range
>        devs() const;
> +   
> +      cl_ulong max_mem_alloc_size() const;
>  
>     private:
>        property_list _props;
> -- 
> 1.8.3.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 229 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20131216/db78c70f/attachment.pgp>


More information about the mesa-dev mailing list