cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
322 stars 92 forks source link

Illegal Variable Name #454

Closed zzzDavid closed 2 years ago

zzzDavid commented 2 years ago

Description

In real use cases, user may input stage name with space or other characters. For example:

 stage_count   = hcl.scalar(0, "stage count", dtype=hcl.UInt(32))

In such case, HCL generates illegal variable names.

Minimal Example

def test():
    hcl.init()
    A = hcl.placeholder((1,2,3,4), dtype=hcl.UInt(33), name="A A")
    B = hcl.compute((1,2,3,4), lambda x,y,z,w: A[x,y,z,w] + 1, name="B B")
    s = hcl.create_schedule([A, B])
    code = hcl.build(s, target="vhls")
    print(code)

Generates VHLS code:

#include <ap_int.h>
#include <ap_fixed.h>
#include <ap_axi_sdata.h>
#include <hls_stream.h>
#include <hls_math.h>
#include <math.h>
#include <stdint.h>
void default_function(ap_uint<33> A A[1][2][3][4], int B B[1][2][3][4]) {
  B_B_x: for (int x = 0; x < 1; ++x) {
    B_B_y: for (int y = 0; y < 2; ++y) {
      B_B_z: for (int z = 0; z < 3; ++z) {
        B_B_w: for (int w = 0; w < 4; ++w) {
          B B[x][y][z][w] = ((int)(A A[x][y][z][w] + (ap_uint<33>)1));
        }
      }
    }
  }
}

Obviously A A and B B would fail the HLS compiler. We should legalize tensor names.