clover: Clean up the interface of the context object slightly.

Tested-by: Tom Stellard <thomas.stellard@amd.com>
This commit is contained in:
Francisco Jerez 2013-09-16 21:38:32 -07:00
parent 5226eacf8d
commit 10284b1d2d
6 changed files with 23 additions and 27 deletions

View file

@ -111,11 +111,11 @@ clGetContextInfo(cl_context d_ctx, cl_context_info param,
break;
case CL_CONTEXT_NUM_DEVICES:
buf.as_scalar<cl_uint>() = ctx.devs.size();
buf.as_scalar<cl_uint>() = ctx.devs().size();
break;
case CL_CONTEXT_DEVICES:
buf.as_vector<cl_device_id>() = descs(map(derefs(), ctx.devs));
buf.as_vector<cl_device_id>() = descs(ctx.devs());
break;
case CL_CONTEXT_PROPERTIES:

View file

@ -63,8 +63,8 @@ clCreateProgramWithBinary(cl_context d_ctx, cl_uint n,
if (!lengths || !binaries)
throw error(CL_INVALID_VALUE);
if (any_of([&](device &dev) {
return !ctx.has_device(dev);
if (any_of([&](const device &dev) {
return !count(dev, ctx.devs());
}, devs))
throw error(CL_INVALID_DEVICE);
@ -133,15 +133,15 @@ clBuildProgram(cl_program d_prog, cl_uint num_devs,
void *user_data) try {
auto &prog = obj(d_prog);
auto devs = (d_devs ? objs(d_devs, num_devs) :
ref_vector<device>(map(derefs(), prog.ctx.devs)));
ref_vector<device>(prog.ctx.devs()));
auto opts = (p_opts ? p_opts : "");
if (bool(num_devs) != bool(d_devs) ||
(!pfn_notify && user_data))
throw error(CL_INVALID_VALUE);
if (any_of([&](device &dev) {
return !prog.ctx.has_device(dev);
if (any_of([&](const device &dev) {
return !count(dev, prog.ctx.devs());
}, devs))
throw error(CL_INVALID_DEVICE);
@ -224,7 +224,7 @@ clGetProgramBuildInfo(cl_program d_prog, cl_device_id d_dev,
auto &prog = obj(d_prog);
auto &dev = obj(d_dev);
if (!prog.ctx.has_device(dev))
if (!count(dev, prog.ctx.devs()))
return CL_INVALID_DEVICE;
switch (param) {

View file

@ -32,7 +32,7 @@ clCreateCommandQueue(cl_context d_ctx, cl_device_id d_dev,
auto &ctx = obj(d_ctx);
auto &dev = obj(d_dev);
if (!ctx.has_device(dev))
if (!count(dev, ctx.devs()))
throw error(CL_INVALID_DEVICE);
if (props & ~(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |

View file

@ -20,20 +20,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#include <algorithm>
#include "core/context.hpp"
using namespace clover;
context::context(const property_list &props,
const ref_vector<device> &devs) :
devs(map(addresses(), devs)), _props(props) {
}
bool
context::has_device(device &dev) const {
return std::count(devs.begin(), devs.end(), &dev);
_props(props), _devs(map(addresses(), devs)) {
}
bool
@ -50,3 +43,8 @@ const context::property_list &
context::props() const {
return _props;
}
context::device_range
context::devs() const {
return map(derefs(), _devs);
}

View file

@ -30,6 +30,7 @@
namespace clover {
class context : public ref_counter, public _cl_context {
private:
typedef adaptor_range<derefs, const std::vector<device *> &> device_range;
typedef clover::property_list<cl_context_properties> property_list;
public:
@ -39,8 +40,6 @@ namespace clover {
context &
operator=(const context &ctx) = delete;
bool has_device(device &dev) const;
bool
operator==(const context &ctx) const;
bool
@ -49,10 +48,12 @@ namespace clover {
const property_list &
props() const;
const std::vector<device *> devs;
device_range
devs() const;
private:
property_list _props;
const std::vector<clover::device *> _devs;
};
}

View file

@ -20,8 +20,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#include <algorithm>
#include "core/format.hpp"
#include "core/memory.hpp"
#include "pipe/p_screen.h"
@ -154,11 +152,10 @@ namespace clover {
PIPE_BIND_TRANSFER_WRITE);
for (auto f : formats) {
if (std::all_of(ctx.devs.begin(), ctx.devs.end(),
[=](const device *dev) {
return dev->pipe->is_format_supported(
dev->pipe, f.second, target, 1, bindings);
}))
if (all_of([=](const device &dev) {
return dev.pipe->is_format_supported(
dev.pipe, f.second, target, 1, bindings);
}, ctx.devs()))
s.insert(f.first);
}