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>
Tue, 27 Feb 2018 09:06:40 +0000 (04:06 -0500)
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

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

index 2f820a9..1bcc943 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>