SWDEV-424956 - Fix OpenCL printf bug while printing vectors of half type

OpenCL printf handling did not process vector of half precision floats properly
 (mainly because compiler packs 2 halfs into a dword and runtime failed to extract the
 individual parts).

 This patch fixes the issue.

Change-Id: Ia1f15ccfb5db52b71c43cfd588dd38f551ee5277
This commit is contained in:
Vikram
2024-01-25 12:58:41 +00:00
zatwierdzone przez Vikram Hegde
rodzic 74cae705ae
commit 6f390f5af9
3 zmienionych plików z 56 dodań i 2 usunięć
+7 -1
Wyświetl plik
@@ -180,6 +180,11 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
case 2:
case 4:
if (printFloat) {
uint32_t arg = *argument;
if (size == 2) {
auto p = reinterpret_cast<const uint16_t*>(argument);
amd::half2float(*p, &arg);
}
static const char* fSpecifiers = "eEfgGa";
std::string fmtF = fmt;
size_t posS = fmtF.find_first_of("%");
@@ -187,7 +192,7 @@ size_t PrintfDbg::outputArgument(const std::string& fmt, bool printFloat, size_t
if (posS != std::string::npos && posE != std::string::npos) {
fmtF.replace(posS + 1, posE - posS, "s");
}
float fArg = *(reinterpret_cast<const float*>(argument));
float fArg = *(reinterpret_cast<const float*>(&arg));
float fSign = copysign(1.0, fArg);
if (std::isinf(fArg) && !std::isnan(fArg)) {
if (fSign < 0) {
@@ -360,6 +365,7 @@ void PrintfDbg::outputDbgBuffer(const device::PrintfInfo& info, const uint32_t*
// Print other elemnts with separator if available
for (int e = 1; e < vectorSize; ++e) {
const char* t = reinterpret_cast<const char*>(s);
// Output the vector separator
outputArgument(sepStr, false, ConstStr, reinterpret_cast<const uint32_t*>(Separator));