clover: Enable cl_khr_fp64 for devices that support doubles v4
authorTom Stellard <thomas.stellard@amd.com>
Wed, 2 Jul 2014 19:42:43 +0000 (15:42 -0400)
committerTom Stellard <thomas.stellard@amd.com>
Thu, 5 Mar 2015 14:07:37 +0000 (14:07 +0000)
v2:
  - Report correct values for CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
    and CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE.
  - Only define cl_khr_fp64 if the extension is supported.
  - Remove trailing space from extension string.
  - Rename device query function from cl_khr_fp64() to
    has_doubles().

v3:
  - Return 0 for device::doubled_fp_confg() when doubles aren't
    supported.

v4:
  - Remove device query for double fp_config.

Reviewed-by: Francisco Jerez <currojerez@riseup.net>
src/gallium/state_trackers/clover/api/device.cpp
src/gallium/state_trackers/clover/core/device.cpp
src/gallium/state_trackers/clover/core/device.hpp

index e82546842580e22b9b25675c781481fc46921fd4..b1f556fac568aaf618b612e6d24e9bff2ab477fb 100644 (file)
@@ -145,7 +145,7 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
       break;
 
    case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE:
-      buf.as_scalar<cl_uint>() = 2;
+      buf.as_scalar<cl_uint>() = dev.has_doubles() ? 2 : 0;
       break;
 
    case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF:
@@ -205,6 +205,21 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
          CL_FP_DENORM | CL_FP_INF_NAN | CL_FP_ROUND_TO_NEAREST;
       break;
 
+   case CL_DEVICE_DOUBLE_FP_CONFIG:
+      if (dev.has_doubles())
+         // This is the "mandated minimum double precision floating-point
+         // capability"
+         buf.as_scalar<cl_device_fp_config>() =
+               CL_FP_FMA
+             | CL_FP_ROUND_TO_NEAREST
+             | CL_FP_ROUND_TO_ZERO
+             | CL_FP_ROUND_TO_INF
+             | CL_FP_INF_NAN
+             | CL_FP_DENORM;
+      else
+         buf.as_scalar<cl_device_fp_config>() = 0;
+      break;
+
    case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE:
       buf.as_scalar<cl_device_mem_cache_type>() = CL_NONE;
       break;
@@ -283,7 +298,7 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
       break;
 
    case CL_DEVICE_EXTENSIONS:
-      buf.as_string() = "";
+      buf.as_string() = dev.has_doubles() ? "cl_khr_fp64" : "";
       break;
 
    case CL_DEVICE_PLATFORM:
@@ -315,7 +330,7 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
       break;
 
    case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE:
-      buf.as_scalar<cl_uint>() = 2;
+      buf.as_scalar<cl_uint>() = dev.has_doubles() ? 2 : 0;
       break;
 
    case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF:
index 688a7dd0893dd374cde08e428568297a8ac44986..c3f3b4e42759360296ef510c998fa97804b5c28d 100644 (file)
@@ -173,6 +173,12 @@ device::image_support() const {
                                       PIPE_COMPUTE_CAP_IMAGES_SUPPORTED)[0];
 }
 
+bool
+device::has_doubles() const {
+   return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
+                                 PIPE_SHADER_CAP_DOUBLES);
+}
+
 std::vector<size_t>
 device::max_block_size() const {
    auto v = get_compute_param<uint64_t>(pipe, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
index 22017005a002655f0b5dba1a0008481038636ad2..de5fc6bb9c41792eff7c2cee29c036bf5a7b7984 100644 (file)
@@ -64,6 +64,7 @@ namespace clover {
       cl_uint max_clock_frequency() const;
       cl_uint max_compute_units() const;
       bool image_support() const;
+      bool has_doubles() const;
 
       std::vector<size_t> max_block_size() const;
       std::string device_name() const;