clover: Switch platform objects to the new model.
authorFrancisco Jerez <currojerez@riseup.net>
Tue, 17 Sep 2013 01:26:04 +0000 (18:26 -0700)
committerFrancisco Jerez <currojerez@riseup.net>
Mon, 21 Oct 2013 17:47:02 +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/platform.cpp
src/gallium/state_trackers/clover/core/device.hpp
src/gallium/state_trackers/clover/core/error.hpp
src/gallium/state_trackers/clover/core/object.hpp
src/gallium/state_trackers/clover/core/platform.cpp
src/gallium/state_trackers/clover/core/platform.hpp

index 495ac41f17e70a48e62bafc5660e25e0196469df..9800779e81a81f80de4104d2ba2b0fb34515d993 100644 (file)
 using namespace clover;
 
 PUBLIC cl_int
-clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type,
+clGetDeviceIDs(cl_platform_id d_platform, cl_device_type device_type,
                cl_uint num_entries, cl_device_id *devices,
                cl_uint *num_devices) {
+   auto &platform = obj(d_platform);
    std::vector<cl_device_id> devs;
 
    if ((!num_entries && devices) ||
@@ -37,9 +38,9 @@ clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type,
       return CL_INVALID_VALUE;
 
    // Collect matching devices
-   for (device &dev : *platform) {
+   for (device &dev : platform) {
       if (((device_type & CL_DEVICE_TYPE_DEFAULT) &&
-           &dev == &platform->front()) ||
+           &dev == &platform.front()) ||
           (device_type & dev.type()))
          devs.push_back(&dev);
    }
@@ -254,7 +255,7 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param,
       break;
 
    case CL_DEVICE_PLATFORM:
-      buf.as_scalar<cl_platform_id>() = &dev->platform;
+      buf.as_scalar<cl_platform_id>() = desc(dev->platform);
       break;
 
    case CL_DEVICE_HOST_UNIFIED_MEMORY:
index 034bbef777773ad26ccf21c9d51da6302f381254..985c2211027c90c5badd3602842c54a6262a1132 100644 (file)
@@ -30,29 +30,28 @@ namespace {
 }
 
 PUBLIC cl_int
-clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms,
-                 cl_uint *num_platforms) {
-   if ((!num_entries && platforms) ||
-       (!num_platforms && !platforms))
+clGetPlatformIDs(cl_uint num_entries, cl_platform_id *rd_platforms,
+                 cl_uint *rnum_platforms) {
+   if ((!num_entries && rd_platforms) ||
+       (!rnum_platforms && !rd_platforms))
       return CL_INVALID_VALUE;
 
-   if (num_platforms)
-      *num_platforms = 1;
-   if (platforms)
-      *platforms = &_clover_platform;
+   if (rnum_platforms)
+      *rnum_platforms = 1;
+   if (rd_platforms)
+      *rd_platforms = desc(_clover_platform);
 
    return CL_SUCCESS;
 }
 
 PUBLIC cl_int
-clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name,
+clGetPlatformInfo(cl_platform_id d_platform, cl_platform_info param,
                   size_t size, void *r_buf, size_t *r_size) try {
    property_buffer buf { r_buf, size, r_size };
 
-   if (platform != &_clover_platform)
-      return CL_INVALID_PLATFORM;
+   obj(d_platform);
 
-   switch (param_name) {
+   switch (param) {
    case CL_PLATFORM_PROFILE:
       buf.as_string() = "FULL_PROFILE";
       break;
index 1dd47487ca55f0f10b2ff4667774966710ad8b48..8252c693f4bcb180189c0686efa281195f79109c 100644 (file)
@@ -32,7 +32,7 @@
 
 namespace clover {
    typedef struct _cl_device_id device;
-   typedef struct _cl_platform_id platform;
+   struct platform;
    class root_resource;
    class hard_event;
 }
index 2b0b6c5e850cbde3406cb9ab3e7148b73aee3752..ab16a81b82c8f019c034a8b98e8d6dc9729bcc1b 100644 (file)
@@ -42,7 +42,7 @@ namespace clover {
    class image;
    class image2d;
    class image3d;
-   typedef struct _cl_platform_id platform;
+   class platform;
    typedef struct _cl_program program;
    typedef struct _cl_sampler sampler;
 
index 807e2f91fc773ca758f21f696d3ab0ecb451e16b..00e94f9e89527cc2b0ebd81f2d8b794c06d0d386 100644 (file)
@@ -179,4 +179,7 @@ namespace clover {
    }
 }
 
+struct _cl_platform_id :
+   public clover::descriptor<clover::platform, _cl_platform_id> {};
+
 #endif
index 6d002e7416d2406a827163f18914abcca13483c4..31e8830760574163efec9b5f174f86af75c74e3f 100644 (file)
@@ -24,7 +24,7 @@
 
 using namespace clover;
 
-_cl_platform_id::_cl_platform_id() {
+platform::platform() {
    int n = pipe_loader_probe(NULL, 0);
    std::vector<pipe_loader_device *> ldevs(n);
 
index af588cc57019ec771ce295403fbd2e98e6cc4fcd..26c65c788bd241bb6a5cd1788b528fb531653a41 100644 (file)
 #include "core/device.hpp"
 
 namespace clover {
-   typedef struct _cl_platform_id platform;
-}
-
-struct _cl_platform_id {
-public:
-   typedef std::vector<clover::device>::iterator iterator;
+   class platform : public _cl_platform_id {
+   public:
+      typedef std::vector<device>::iterator iterator;
 
-   _cl_platform_id();
+      platform();
 
-   ///
-   /// Container of all compute devices that are available in the platform.
-   ///
-   /// @{
-   iterator begin() {
-      return devs.begin();
-   }
+      ///
+      /// Container of all compute devices that are available in the platform.
+      ///
+      /// @{
+      iterator begin() {
+         return devs.begin();
+      }
 
-   iterator end() {
-      return devs.end();
-   }
+      iterator end() {
+         return devs.end();
+      }
 
-   clover::device &front() {
-      return devs.front();
-   }
+      device &front() {
+         return devs.front();
+      }
 
-   clover::device &back() {
-      return devs.back();
-   }
-   /// @}
+      device &back() {
+         return devs.back();
+      }
+      /// @}
 
-protected:
-   std::vector<clover::device> devs;
-};
+   protected:
+      std::vector<device> devs;
+   };
+}
 
 #endif