clover: Query and export half precision support
authorJan Vesely <jan.vesely@rutgers.edu>
Fri, 1 Sep 2017 21:48:39 +0000 (17:48 -0400)
committerJan Vesely <jan.vesely@rutgers.edu>
Mon, 18 Sep 2017 14:45:02 +0000 (10:45 -0400)
v2: PIPE_CAP_HALFS -> PIPE_SHADER_CAP_FP16
    has_halfs -> has_halves

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
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 b202102389fc75de4c7ec4d7b8145741804e8a44..26e88aadc73d6b7a3a9798317bcad7dfdfedbad8 100644 (file)
@@ -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_halves() ? 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_halves() ? " 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_halves() ? 8 : 0;
       break;
 
    case CL_DEVICE_OPENCL_C_VERSION:
index fc74bd51a9eafde0a2e2b9282adbf664e404f466..c0ee0acaaf9ac6c73e5e6d9ea07df0f17577b816 100644 (file)
@@ -190,6 +190,12 @@ device::has_doubles() const {
    return pipe->get_param(pipe, PIPE_CAP_DOUBLES);
 }
 
+bool
+device::has_halves() const {
+   return pipe->get_shader_param(pipe, PIPE_SHADER_COMPUTE,
+                                 PIPE_SHADER_CAP_FP16);
+}
+
 bool
 device::has_unified_memory() const {
    return pipe->get_param(pipe, PIPE_CAP_UMA);
index 4e11519421a9ca23149161a0eaab04a96a836321..c61be790a94232626143d310911474c26e26e657 100644 (file)
@@ -67,6 +67,7 @@ namespace clover {
       cl_uint max_compute_units() const;
       bool image_support() const;
       bool has_doubles() const;
+      bool has_halves() const;
       bool has_unified_memory() const;
       cl_uint mem_base_addr_align() const;