[Mesa-dev] [PATCH] clover: Support multiple devices in clCreateContextFromType()

Francisco Jerez currojerez at riseup.net
Wed May 15 02:19:01 PDT 2013


Tom Stellard <tom at stellard.net> writes:

> From: Tom Stellard <thomas.stellard at amd.com>
>
Hi Tom.  This should probably leave out any devices that don't match the
type argument.  To avoid duplicating the type-matching logic I think the
best would be to keep it implemented in terms of clGetDeviceIDs, just
call it twice to get the number of vector elements you need to allocate.

> ---
>  src/gallium/state_trackers/clover/api/context.cpp | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/src/gallium/state_trackers/clover/api/context.cpp b/src/gallium/state_trackers/clover/api/context.cpp
> index 3717441..e0fed31 100644
> --- a/src/gallium/state_trackers/clover/api/context.cpp
> +++ b/src/gallium/state_trackers/clover/api/context.cpp
> @@ -22,6 +22,7 @@
>  
>  #include "api/util.hpp"
>  #include "core/context.hpp"
> +#include "core/platform.hpp"
>  
>  using namespace clover;
>  
> @@ -63,18 +64,22 @@ clCreateContextFromType(const cl_context_properties *props,
>                          void *user_data, cl_int *errcode_ret) try {
>     cl_platform_id platform;
>     cl_uint num_platforms;
> -   cl_device_id dev;
>     cl_int ret;
> +   std::vector<cl_device_id> devs;
>  
>     ret = clGetPlatformIDs(1, &platform, &num_platforms);
>     if (ret || !num_platforms)
>        throw error(CL_INVALID_PLATFORM);
>  
> -   ret = clGetDeviceIDs(platform, type, 1, &dev, 0);
> -   if (ret)
> +   if (platform->begin() == platform->end())
>        throw error(CL_DEVICE_NOT_FOUND);
>  
> -   return clCreateContext(props, 1, &dev, pfn_notify, user_data, errcode_ret);
> +   for (clover::platform::iterator i = platform->begin(), e = platform->end();
> +                                                         i != e; ++i) {
> +      devs.push_back(&*i);
> +   }
> +
> +   return clCreateContext(props, devs.size(), devs.data(), pfn_notify, user_data, errcode_ret);
>  
>  } catch(error &e) {
>     ret_error(errcode_ret, e);
-------------- 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/20130515/208e5a2d/attachment.pgp>


More information about the mesa-dev mailing list