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:
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);
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);
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) {
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 |
// 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
context::props() const {
return _props;
}
+
+context::device_range
+context::devs() const {
+ return map(derefs(), _devs);
+}
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:
context &
operator=(const context &ctx) = delete;
- bool has_device(device &dev) const;
-
bool
operator==(const context &ctx) const;
bool
const property_list &
props() const;
- const std::vector<device *> devs;
+ device_range
+ devs() const;
private:
property_list _props;
+ const std::vector<clover::device *> _devs;
};
}
// OTHER DEALINGS IN THE SOFTWARE.
//
-#include <algorithm>
-
#include "core/format.hpp"
#include "core/memory.hpp"
#include "pipe/p_screen.h"
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);
}