From e36aff2ea93d9a9ff89320f77d4e2917c6d18697 Mon Sep 17 00:00:00 2001 From: Athish Pranav D <105591739+Athishpranav2003@users.noreply.github.com> Date: Wed, 12 Mar 2025 18:47:33 +0530 Subject: Corrected offset for args in printf (#84) Signed-off-by: Athishpranav2003 Co-authored-by: Anu Co-authored-by: WilliamMTK --- src/cuda-sim/cuda_device_printf.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/cuda-sim/cuda_device_printf.cc') diff --git a/src/cuda-sim/cuda_device_printf.cc b/src/cuda-sim/cuda_device_printf.cc index 1da6b85..69ebc63 100644 --- a/src/cuda-sim/cuda_device_printf.cc +++ b/src/cuda-sim/cuda_device_printf.cc @@ -38,6 +38,7 @@ void my_cuda_printf(const char *fmtstr, const char *arg_list) { unsigned arg_offset = 0; char buf[64]; bool in_fmt = false; + uint8_t acc = 0; while (fmtstr[i]) { char c = fmtstr[i++]; if (!in_fmt) { @@ -60,12 +61,19 @@ void my_cuda_printf(const char *fmtstr, const char *arg_list) { void *ptr = (void *)&arg_list[arg_offset]; // unsigned long long value = ((unsigned long long*)arg_list)[arg_offset]; if (c == 'u' || c == 'd') { - fprintf(fp, buf, *((unsigned long long *)ptr)); + acc++; + fprintf(fp, buf, *((unsigned *)ptr)); + arg_offset += 4; } else if (c == 'f') { - double tmp = *((double *)ptr); + if (acc%2) { + arg_offset += 4; + ptr = (void *)&arg_list[arg_offset]; + } + float tmp = *((float *)ptr); fprintf(fp, buf, tmp); + arg_offset += 8; + acc = 0; } - arg_offset++; in_fmt = false; } } -- cgit v1.3