Account for differences in nan with fp16 comparison
authorPiers Daniell <pdaniell@nvidia.com>
Thu, 15 Feb 2018 19:33:15 +0000 (12:33 -0700)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 22 Mar 2018 15:01:28 +0000 (11:01 -0400)
When comparing fp16 values it's not possible to use a bitwise
comparison because there can be many different bit patterns
representing nan values, and all nans are equal. This CL updates
the computeCheckBuffersFloats function which compares two
buffers of fp16 values to take into account different forms
of nan.

Affects:

dEQP-VK.spirv_assembly.instruction.compute.16bit_storage.uniform_16_to_16.stress_test

Components: Vulkan

VK-GL-CTS issue: 1018

Change-Id: I77013b49ce070d9615b287eae24dd32731b314b1
(cherry picked from commit 92d5909ab99bc97dc2ae4dd67e1cfa592dafb246)

external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsm16bitStorageTests.cpp

index ba2078e..699a017 100644 (file)
@@ -90,6 +90,7 @@ using namespace vk;
 using std::map;
 using std::string;
 using std::vector;
+using tcu::Float16;
 using tcu::IVec3;
 using tcu::IVec4;
 using tcu::RGBA;
@@ -169,7 +170,22 @@ bool computeCheckBuffersFloats (const std::vector<BufferSp>&       originalFloats,
 {
        std::vector<deUint8> result;
        originalFloats.front()->getBytes(result);
-       return deMemCmp(&result[0], outputAllocs.front()->getHostPtr(), result.size()) == 0;
+
+       const deUint16 * results = reinterpret_cast<const deUint16 *>(&result[0]);
+       const deUint16 * expected = reinterpret_cast<const deUint16 *>(outputAllocs.front()->getHostPtr());
+
+       for (size_t i = 0; i < result.size() / sizeof (deUint16); ++i)
+       {
+               if (results[i] == expected[i])
+                       continue;
+
+               if (Float16(results[i]).isNaN() && Float16(expected[i]).isNaN())
+                       continue;
+
+               return false;
+       }
+
+       return true;
 }
 
 template<RoundingModeFlags RoundingMode>