[Mesa-dev] [PATCH 2/2] clover: Enable cl_khr_fp64 for devices that support doubles v3

Tom Stellard thomas.stellard at amd.com
Wed Jul 2 12:48:17 PDT 2014


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_fp86() to
    has_doubles().

v3:
  - Return 0 for device::doubled_fp_confg() when doubles aren't
    supported.
---
 src/gallium/state_trackers/clover/api/device.cpp    | 10 +++++++---
 src/gallium/state_trackers/clover/core/device.cpp   | 21 +++++++++++++++++++++
 src/gallium/state_trackers/clover/core/device.hpp   |  2 ++
 src/gallium/state_trackers/clover/core/program.cpp  |  5 ++++-
 .../state_trackers/clover/llvm/invocation.cpp       |  1 -
 5 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/src/gallium/state_trackers/clover/api/device.cpp b/src/gallium/state_trackers/clover/api/device.cpp
index 3b91e9e..5427492 100644
--- a/src/gallium/state_trackers/clover/api/device.cpp
+++ b/src/gallium/state_trackers/clover/api/device.cpp
@@ -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:
@@ -204,6 +204,10 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
       buf.as_scalar<cl_device_fp_config>() = dev.single_fp_config();
       break;
 
+   case CL_DEVICE_DOUBLE_FP_CONFIG:
+      buf.as_scalar<cl_device_fp_config>() = dev.double_fp_config();
+      break;
+
    case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE:
       buf.as_scalar<cl_device_mem_cache_type>() = CL_NONE;
       break;
@@ -282,7 +286,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:
@@ -314,7 +318,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:
diff --git a/src/gallium/state_trackers/clover/core/device.cpp b/src/gallium/state_trackers/clover/core/device.cpp
index 498e7d9..cfbe95a 100644
--- a/src/gallium/state_trackers/clover/core/device.cpp
+++ b/src/gallium/state_trackers/clover/core/device.cpp
@@ -175,6 +175,27 @@ device::single_fp_config() const {
    return CL_FP_DENORM | CL_FP_INF_NAN | CL_FP_ROUND_TO_NEAREST;
 }
 
+cl_device_fp_config
+device::double_fp_config() const {
+   if (!has_doubles())
+      return 0;
+
+   // TODO: Get these from somewhere. This is the "mandated minimum double
+   // precision floating-point capability"
+   return 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;
+}
+
+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);
diff --git a/src/gallium/state_trackers/clover/core/device.hpp b/src/gallium/state_trackers/clover/core/device.hpp
index 93f9091..a1899bc 100644
--- a/src/gallium/state_trackers/clover/core/device.hpp
+++ b/src/gallium/state_trackers/clover/core/device.hpp
@@ -64,6 +64,8 @@ namespace clover {
       cl_uint max_clock_frequency() const;
       cl_uint max_compute_units() const;
       cl_device_fp_config single_fp_config() const;
+      cl_device_fp_config double_fp_config() const;
+      bool has_doubles() const;
 
       std::vector<size_t> max_block_size() const;
       std::string device_name() const;
diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp
index e09c3aa..f65f321 100644
--- a/src/gallium/state_trackers/clover/core/program.cpp
+++ b/src/gallium/state_trackers/clover/core/program.cpp
@@ -95,7 +95,10 @@ program::build_status(const device &dev) const {
 
 std::string
 program::build_opts(const device &dev) const {
-   return _opts.count(&dev) ? _opts.find(&dev)->second : "";
+   std::string opts = _opts.count(&dev) ? _opts.find(&dev)->second : "";
+   if (dev.has_doubles())
+      opts.append(" -Dcl_khr_fp64");
+   return opts;
 }
 
 std::string
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index 5d2efc4..f2b4fd9 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -183,7 +183,6 @@ namespace {
 
       // clc.h requires that this macro be defined:
       c.getPreprocessorOpts().addMacroDef("cl_clang_storage_class_specifiers");
-      c.getPreprocessorOpts().addMacroDef("cl_khr_fp64");
 
       c.getLangOpts().NoBuiltin = true;
       c.getTargetOpts().Triple = triple;
-- 
1.8.1.5



More information about the mesa-dev mailing list