Kuree / kratos

:crossed_swords: Debuggable hardware generator
https://kratos-doc.readthedocs.io
BSD 2-Clause "Simplified" License
67 stars 9 forks source link

operand type ** or pow() not supported for _kratos.Param #152

Closed philipaxer closed 4 years ago

philipaxer commented 4 years ago

Hi, This is a feature request to extend arithmetic on parameters to include power.

Generator parameters are typically used to derive downstream values using arithmetic expressions. E.g. in memory implemententations, the memory depth is derived by 2**addr_width. The result is then used to size the memory array.

        addr_width = self.parameter("ADDR_WIDTH", 8,
                                           default_value=8)   
        mem = self.var("mem", width=data_width, size= 2**addr_width)

The above statement is giving me an error, but is a common use-case.

Ideally, i would like to generate a local parameter in the target sv as follows:

    localparam DATA_DEPTH=2**ADDR_WIDTH;
Kuree commented 4 years ago

Thank you for the request. I will put this on my TODO list.

There are actually two features requested:

  1. support power operator in a safe and synthesizable fashion
  2. support parametrization on size

Power operator should be straightforward to implement.

Parameterization on size/width, on the other hand, is an afterthought after most of the system design is done. Initially we don't allow such behavior, since you can always use Python metaprogramming do to the work. For instance, in your example:

addr_width = 8  # this is a generator parameter as Python int
mem = self.var("mem", width=data_width, size= 2**addr_width)

This will generate a perfectly fine circuit. The downside for that, as we've seen from many other generator frameworks, is that a numbers of different RTL modules get generated simply because the width is different. That's why we introduce the width parameterization later on to improve the codegen quality.

That being said, since this is not a blocking issue, it might not get implemented in the near future (and it will also need some significant rewrite on how we do width checking).

Kuree commented 4 years ago

See test example here: https://github.com/Kuree/kratos/blob/master/tests/test_generator.py#L1967