Pass vendor macro to opencl kernel
authorAlexander Karsakov <alexander.karsakov@itseez.com>
Wed, 5 Mar 2014 11:04:44 +0000 (15:04 +0400)
committerAlexander Karsakov <alexander.karsakov@itseez.com>
Fri, 7 Mar 2014 08:57:29 +0000 (12:57 +0400)
modules/core/include/opencv2/core/ocl.hpp
modules/core/src/ocl.cpp

index 686a4f3..f7fae9e 100644 (file)
@@ -87,7 +87,7 @@ public:
     String name() const;
     String extensions() const;
     String version() const;
-    String vendor() const;
+    String vendorName() const;
     String OpenCL_C_Version() const;
     String OpenCLVersion() const;
     int deviceVersionMajor() const;
@@ -164,14 +164,13 @@ public:
     enum
     {
         UNKNOWN_VENDOR=0,
-        AMD=1,
-        INTEL=2,
-        NVIDIA=3
+        VENDOR_AMD=1,
+        VENDOR_INTEL=2,
+        VENDOR_NVIDIA=3
     };
-
-    bool isAMD() const;
-    bool isIntel() const;
-    bool isNvidia() const;
+    int vendorID() const;
+    inline bool isAMD() const { return vendorID() == VENDOR_AMD; };
+    inline bool isIntel() const { return vendorID() == VENDOR_INTEL; };
 
     int maxClockFrequency() const;
     int maxComputeUnits() const;
index 6c2bd78..1cbbc2a 100644 (file)
@@ -1713,16 +1713,16 @@ struct Device::Impl
         String deviceVersion_ = getStrProp(CL_DEVICE_VERSION);
         parseDeviceVersion(deviceVersion_, deviceVersionMajor_, deviceVersionMinor_);
 
-        vendorName = getStrProp(CL_DEVICE_VENDOR);
-        if (vendorName == "Advanced Micro Devices, Inc." ||
-            vendorName == "AMD")
-            vendor_ = AMD;
-        else if (vendorName == "Intel(R) Corporation")
-            vendor_ = INTEL;
-        else if (vendorName == "NVIDIA Corporation")
-            vendor_ = NVIDIA;
+        vendorName_ = getStrProp(CL_DEVICE_VENDOR);
+        if (vendorName_ == "Advanced Micro Devices, Inc." ||
+            vendorName_ == "AMD")
+            vendorID_ = VENDOR_AMD;
+        else if (vendorName_ == "Intel(R) Corporation")
+            vendorID_ = VENDOR_INTEL;
+        else if (vendorName_ == "NVIDIA Corporation")
+            vendorID_ = VENDOR_NVIDIA;
         else
-            vendor_ = UNKNOWN_VENDOR;
+            vendorID_ = UNKNOWN_VENDOR;
     }
 
     template<typename _TpCL, typename _TpOut>
@@ -1765,8 +1765,8 @@ struct Device::Impl
     int deviceVersionMajor_;
     int deviceVersionMinor_;
     String driverVersion_;
-    String vendorName;
-    int vendor_;
+    String vendorName_;
+    int vendorID_;
 };
 
 
@@ -1826,8 +1826,11 @@ String Device::extensions() const
 String Device::version() const
 { return p ? p->version_ : String(); }
 
-String Device::vendor() const
-{ return p ? p->vendorName : String(); }
+String Device::vendorName() const
+{ return p ? p->vendorName_ : String(); }
+
+int Device::vendorID() const
+{ return p ? p->vendorID_ : 0; }
 
 String Device::OpenCL_C_Version() const
 { return p ? p->getStrProp(CL_DEVICE_OPENCL_C_VERSION) : String(); }
@@ -1938,21 +1941,6 @@ size_t Device::imageMaxArraySize() const
 { CV_REQUIRE_OPENCL_1_2_ERROR; }
 #endif
 
-bool Device::isAMD() const
-{
-  return p->vendor_ == AMD;
-}
-
-bool Device::isIntel() const
-{
-  return p->vendor_ == INTEL;
-}
-
-bool Device::isNvidia() const
-{
-  return p->vendor_ == NVIDIA;
-}
-
 int Device::maxClockFrequency() const
 { return p ? p->getProp<cl_uint, int>(CL_DEVICE_MAX_CLOCK_FREQUENCY) : 0; }
 
@@ -3037,6 +3025,12 @@ struct Program::Impl
             for( i = 0; i < n; i++ )
                 deviceList[i] = ctx.device(i).ptr();
 
+            Device device = Device::getDefault();
+            if (device.isAMD())
+                buildflags += " -D AMD_DEVICE";
+            else if (device.isIntel())
+                buildflags += " -D INTEL_DEVICE";
+
             retval = clBuildProgram(handle, n,
                                     (const cl_device_id*)deviceList,
                                     buildflags.c_str(), 0, 0);