[Mesa-dev] [PATCH 2/2] clover: Query and export half precision support

Jan Vesely jan.vesely at rutgers.edu
Sat Sep 2 00:55:17 UTC 2017


Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---

 src/gallium/state_trackers/clover/api/device.cpp  | 14 +++++++++++---
 src/gallium/state_trackers/clover/core/device.cpp |  5 +++++
 src/gallium/state_trackers/clover/core/device.hpp |  1 +
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/gallium/state_trackers/clover/api/device.cpp b/src/gallium/state_trackers/clover/api/device.cpp
index b202102389..7b31b10e15 100644
--- a/src/gallium/state_trackers/clover/api/device.cpp
+++ b/src/gallium/state_trackers/clover/api/device.cpp
@@ -150,7 +150,7 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
       break;
 
    case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF:
-      buf.as_scalar<cl_uint>() = 0;
+      buf.as_scalar<cl_uint>() = dev.has_halfs() ? 8 : 0;
       break;
 
    case CL_DEVICE_MAX_CLOCK_FREQUENCY:
@@ -213,6 +213,13 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
       buf.as_scalar<cl_uint>() = 128;
       break;
 
+   case CL_DEVICE_HALF_FP_CONFIG:
+      // This is the "mandated minimum half precision floating-point
+      // capability" for OpenCL 1.x.
+      buf.as_scalar<cl_device_fp_config>() =
+         CL_FP_INF_NAN | CL_FP_ROUND_TO_NEAREST;
+      break;
+
    case CL_DEVICE_SINGLE_FP_CONFIG:
       // This is the "mandated minimum single precision floating-point
       // capability" for OpenCL 1.1.  In OpenCL 1.2, nothing is required for
@@ -329,7 +336,8 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
          " cl_khr_local_int32_base_atomics"
          " cl_khr_local_int32_extended_atomics"
          " cl_khr_byte_addressable_store"
-         + std::string(dev.has_doubles() ? " cl_khr_fp64" : "");
+         + std::string(dev.has_doubles() ? " cl_khr_fp64" : "")
+         + std::string(dev.has_halfs() ? " cl_khr_fp16" : "");
       break;
 
    case CL_DEVICE_PLATFORM:
@@ -365,7 +373,7 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
       break;
 
    case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF:
-      buf.as_scalar<cl_uint>() = 0;
+      buf.as_scalar<cl_uint>() = dev.has_halfs() ? 8 : 0;
       break;
 
    case CL_DEVICE_OPENCL_C_VERSION:
diff --git a/src/gallium/state_trackers/clover/core/device.cpp b/src/gallium/state_trackers/clover/core/device.cpp
index fc74bd51a9..f38696cc44 100644
--- a/src/gallium/state_trackers/clover/core/device.cpp
+++ b/src/gallium/state_trackers/clover/core/device.cpp
@@ -191,6 +191,11 @@ device::has_doubles() const {
 }
 
 bool
+device::has_halfs() const {
+   return pipe->get_param(pipe, PIPE_CAP_HALFS);
+}
+
+bool
 device::has_unified_memory() const {
    return pipe->get_param(pipe, PIPE_CAP_UMA);
 }
diff --git a/src/gallium/state_trackers/clover/core/device.hpp b/src/gallium/state_trackers/clover/core/device.hpp
index 4e11519421..4ef53de486 100644
--- a/src/gallium/state_trackers/clover/core/device.hpp
+++ b/src/gallium/state_trackers/clover/core/device.hpp
@@ -67,6 +67,7 @@ namespace clover {
       cl_uint max_compute_units() const;
       bool image_support() const;
       bool has_doubles() const;
+      bool has_halfs() const;
       bool has_unified_memory() const;
       cl_uint mem_base_addr_align() const;
 
-- 
2.13.5



More information about the mesa-dev mailing list