EPFL-LAP / dynamatic

DHLS (Dynamic High-Level Synthesis) compiler based on MLIR
Other
64 stars 19 forks source link

[scf] memory out-of-bound error #119

Open Jiahui17 opened 3 months ago

Jiahui17 commented 3 months ago

Benchmark:

symm_float.c

Script:

set-dynamatic-path ./dynamatic;   set-src ./dynamatic/integration-test/symm_float/symm_float.c;   set-clock-period 5;   compile  ;   write-hdl --hdl verilog;   simulate;   synthesize;   exit

Error:

[INFO] Compiled source to affine
[INFO] Ran memory analysis
[INFO] Compiled affine to scf
[INFO] Compiled scf to cf
[INFO] Applied standard transformations to cf
[INFO] Applied Dynamatic transformations to cf
[INFO] Compiled cf to handshake
[INFO] Applied transformations to handshake
[INFO] Built kernel for profiling
[INFO] Ran kernel for profiling
loc("/home/jxu/Repositories/dhls-utils/./dynamatic/integration-test/symm_float/out/comp/cf_dyn_transformed.mlir":22:10): error: 'memref.load' op Out-of-bounds access to memory '0'. Memory has 900 elements but requested element 900
[FATAL] Failed to profile cf-level

Note that the source program can be compiled and ran by g++ without any error

lucas-rami commented 3 months ago

Thanks for the report. I diagnosed the problem and unfortunately it is a mean one I do not have time to fix right now.

The issue is in our semi-custom ScfToCf conversion pass. When lowering for loops we have an optimization that upgrades the iterator's normal signed comparison (slt) to an unsigned comparison (ult) when our heuristic detects that both the iterator and bound are necessarily positive (see here). We do this because it allows us to perform more aggressive bitwidth optimizations down in Handshake. Unfortunately it looks like our heuristic is faulty and in that case incorrectly upgrades the innermost loop's comparator from signed to unsigned, when the upper bound (j - 1) can in fact be negative. This makes the cf-level simulator interprets the bound as unsigned when it is negative, so it becomes a very large number that overflows the A array.