clover: Define a few convenience equality operators.
authorFrancisco Jerez <currojerez@riseup.net>
Tue, 17 Sep 2013 04:11:16 +0000 (21:11 -0700)
committerFrancisco Jerez <currojerez@riseup.net>
Mon, 21 Oct 2013 17:47:03 +0000 (10:47 -0700)
Tested-by: Tom Stellard <thomas.stellard@amd.com>
src/gallium/state_trackers/clover/api/device.cpp
src/gallium/state_trackers/clover/api/event.cpp
src/gallium/state_trackers/clover/api/kernel.cpp
src/gallium/state_trackers/clover/core/context.cpp
src/gallium/state_trackers/clover/core/context.hpp
src/gallium/state_trackers/clover/core/device.cpp
src/gallium/state_trackers/clover/core/device.hpp
src/gallium/state_trackers/clover/core/format.hpp
src/gallium/state_trackers/clover/core/memory.cpp
src/gallium/state_trackers/clover/core/memory.hpp

index 7e99f74..dd7ef40 100644 (file)
@@ -40,7 +40,7 @@ clGetDeviceIDs(cl_platform_id d_platform, cl_device_type device_type,
    // Collect matching devices
    for (device &dev : platform) {
       if (((device_type & CL_DEVICE_TYPE_DEFAULT) &&
-           &dev == &platform.front()) ||
+           dev == platform.front()) ||
           (device_type & dev.type()))
          d_devs.push_back(desc(dev));
    }
index 1395c54..4ed96b0 100644 (file)
@@ -63,7 +63,7 @@ clWaitForEvents(cl_uint num_evs, const cl_event *d_evs) try {
    auto evs = objs(d_evs, num_evs);
 
    for (auto &ev : evs) {
-      if (&ev.ctx != &evs.front().ctx)
+      if (ev.ctx != evs.front().ctx)
          throw error(CL_INVALID_CONTEXT);
 
       if (ev.status() < 0)
@@ -199,7 +199,7 @@ clEnqueueWaitForEvents(cl_command_queue d_q, cl_uint num_evs,
    auto evs = objs(d_evs, num_evs);
 
    for (auto &ev : evs) {
-         if (&ev.ctx != &q.ctx)
+         if (ev.ctx != q.ctx)
             throw error(CL_INVALID_CONTEXT);
    }
 
index 15b4c14..dd742c3 100644 (file)
@@ -202,9 +202,9 @@ namespace {
    void
    validate_common(command_queue &q, kernel &kern,
                    const ref_vector<event> &deps) {
-      if (&kern.prog.ctx != &q.ctx ||
+      if (kern.prog.ctx != q.ctx ||
           any_of([&](const event &ev) {
-                return &ev.ctx != &q.ctx;
+                return ev.ctx != q.ctx;
              }, deps))
          throw error(CL_INVALID_CONTEXT);
 
index 7b79f82..f4f9800 100644 (file)
@@ -36,6 +36,16 @@ context::has_device(device &dev) const {
    return std::count(devs.begin(), devs.end(), &dev);
 }
 
+bool
+context::operator==(const context &ctx) const {
+   return this == &ctx;
+}
+
+bool
+context::operator!=(const context &ctx) const {
+   return this != &ctx;
+}
+
 const context::property_list &
 context::props() const {
    return _props;
index 6fda061..576e952 100644 (file)
@@ -39,6 +39,11 @@ namespace clover {
 
       bool has_device(device &dev) const;
 
+      bool
+      operator==(const context &ctx) const;
+      bool
+      operator!=(const context &ctx) const;
+
       const property_list &
       props() const;
 
index 9f6407e..3932270 100644 (file)
@@ -68,6 +68,11 @@ device::operator=(device dev) {
    return *this;
 }
 
+bool
+device::operator==(const device &dev) const {
+   return this == &dev;
+}
+
 cl_device_type
 device::type() const {
    switch (ldev->type) {
index 42e32a1..fd6b457 100644 (file)
@@ -44,6 +44,9 @@ namespace clover {
 
       device &operator=(device dev);
 
+      bool
+      operator==(const device &dev) const;
+
       cl_device_type type() const;
       cl_uint vendor_id() const;
       size_t max_images_read() const;
index 26439c7..a8b7053 100644 (file)
@@ -48,4 +48,15 @@ operator<(const cl_image_format &a, const cl_image_format &b) {
            a.image_channel_data_type < b.image_channel_data_type);
 }
 
+static inline bool
+operator==(const cl_image_format &a, const cl_image_format &b) {
+   return (a.image_channel_order == b.image_channel_order &&
+           a.image_channel_data_type == b.image_channel_data_type);
+}
+
+static inline bool
+operator!=(const cl_image_format &a, const cl_image_format &b) {
+   return !(a == b);
+}
+
 #endif
index 106936b..1c38597 100644 (file)
@@ -38,6 +38,11 @@ memory_obj::~memory_obj() {
    _destroy_notify();
 }
 
+bool
+memory_obj::operator==(const memory_obj &obj) const {
+   return this == &obj;
+}
+
 void
 memory_obj::destroy_notify(std::function<void ()> f) {
    _destroy_notify = f;
index 7c53008..86f7dda 100644 (file)
@@ -43,6 +43,9 @@ namespace clover {
    public:
       virtual ~memory_obj();
 
+      bool
+      operator==(const memory_obj &obj) const;
+
       virtual cl_mem_object_type type() const = 0;
       virtual clover::resource &resource(command_queue &q) = 0;