PipelineC icon indicating copy to clipboard operation
PipelineC copied to clipboard

Isolate not to be pipelined local static variable feedback within functions so user doesn't have to

Open JulianKemmerer opened this issue 2 years ago • 0 comments

Note that accumulate isnt a perfect example below since actually has exotic pipelining possibilities for integer math.


Consider a multiply (can be pipelined) and accumulate (cannot be pipelined, normally)

If the user wrote this:

uint32_t mult_accum(uint32_t x, uint32_t y)
{
  uint32_t prod = x * y;
  static uint32_t total = 0;
  total += prod;
  return total;
}

The entire multiply and accumulate would take place in a single cycle. The function contains a static local variable and cannot be easily pipelined over multiple cycle since it has feedback state.

The user can write code like so to use autopipelining:

// The accumulation cannot be pipelined 
// (need result in a single cycle)
// So isolate the local state 
// variable function doing just accumulate
uint32_t accum(uint32_t inc){
  static uint32_t total = 0.0;
  total += inc;
  return total;
}
// Everything outside of 'accum'
// (the multiply) is autopipelined
uint32_t mult_accum(uint32_t x, uint32_t y)
{
  uint32_t prod = x * y;
  return accum(prod);
}

The static local variable is isolated to its own not-pipelined region/separate function by the user. This allows the multiply to be pipelined.

This ~transformation / ~optimization pass should be done by a tool - implement that.

JulianKemmerer avatar Jun 12 '22 00:06 JulianKemmerer