Skip to content

Possible bug in generated HLS #38

@wyanzhao

Description

@wyanzhao

Hi, I am trying to use Halide-HLS to write a simple HLS program. But I found in some cases, the tool will produce incorrect HLS results.
Here's the given Halide C++ code:

MyPipeline() : input(UInt(64), 1, "input"), A("A"), B("B"), C("C"), hw_output("hw_output")

{

    // define the algorithm

    A = BoundaryConditions::repeat_edge(input);

    Expr constant(((uint64_t)(274877906943)));

    output(x) =  A(x) & constant;

    // define common schedule: tile output

    args.push_back(input);

}

This program supposed to clear the 39th and 40th bit of A. However, in the generated HLS, the code will be:

 for (int _p2_output_s0_x = _21; _p2_output_s0_x < _21 + _137; _p2_output_s0_x++)

  {

   int32_t _138 = _14 + _15;

   int32_t _139 = _138 + -1;

   int32_t _140 = min(_p2_output_s0_x, _139);

   int32_t _141 = _140 - _14;

   int32_t _142 = max(_141, 0);

   uint64_t _143 = ((const uint64_t *)_input)[_142];

   uint64_t _144 = _143 & 63;

   int32_t _145 = _p2_output_s0_x - _21;

   ((uint64_t *)_p2_output)[_145] = _144;

  } // for _p2_output_s0_x

  int32_t _146 = _136 - _132;

  for (int _p2_output_s0_x = _132; _p2_output_s0_x < _132 + _146; _p2_output_s0_x++)

  {

   int32_t _147 = _p2_output_s0_x - _14;

   uint64_t _148 = ((const uint64_t *)_input)[_147];

   uint64_t _149 = _148 & 63;

   int32_t _150 = _p2_output_s0_x - _21;

   ((uint64_t *)_p2_output)[_150] = _149;

  } // for _p2_output_s0_x

Where the constant expr will become 63, instead of the original 274877906943. And this will produce incorrect results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions