Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IR] Attach uint attributes #283

Merged
merged 1 commit into from
Jan 1, 2025
Merged

Conversation

chhzh123
Copy link
Member

@chhzh123 chhzh123 commented Jan 1, 2025

Description

This PR attaches the missing unsigned attributes to the MLIR operations in order to preserve the signedness when generating the backend HLS code.

Examples

def casting():
    buf1: UInt(15)[16, 16] = 0
    buf2: float32[16, 16]

    for i, j in allo.grid(16, 16):
        buf2[i, j] = float(buf1[i, j] + buf1[j, i])

s = allo.customize(casting)
print(s.module)
code = s.build(target="vhls")
print(code)
void casting(

) {     // L2
  ap_uint<15> buf1[16][16];     // L5
  for (int v1 = 0; v1 < 16; v1++) {     // L6
    for (int v2 = 0; v2 < 16; v2++) {   // L6
      buf1[v1][v2] = 0; // L6
    }
  }
  float buf2[16][16];   // L7
  l_S_i_j_0_i: for (int i = 0; i < 16; i++) {   // L8
    l_j: for (int j = 0; j < 16; j++) { // L9
      ap_uint<15> v6 = buf1[i][j];      // L10
      ap_uint<15> v7 = buf1[j][i];      // L11
      uint16_t v8 = v6; // L12
      uint16_t v9 = v7; // L13
      uint16_t v10 = v8 + v9;   // L14
      float v11 = v10;  // L15
      buf2[i][j] = v11; // L16
    }
  }
}

Checklist

  • PR's title starts with a category (e.g. [Bugfix], [IR], [Builder], etc)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage (It would be better to provide ~2 different test cases to test the robustness of your code)
  • Code is well-documented

@chhzh123 chhzh123 merged commit 90a0efe into cornell-zhang:main Jan 1, 2025
1 check passed
@chhzh123 chhzh123 deleted the uint_op branch January 1, 2025 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant