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
کامیت شده توسط Vikram Hegde
والد 74cae705ae
کامیت 6f390f5af9
3فایلهای تغییر یافته به همراه56 افزوده شده و 2 حذف شده
@@ -291,6 +291,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("%");
@@ -298,7 +303,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 (isinf(fArg) && !isnan(fArg)) {
if (fSign < 0) {
@@ -466,6 +471,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));