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

Question about using functions in unrolled loop #418

Closed
Mark1626 opened this issue Feb 28, 2024 · 1 comment · Fixed by #419
Closed

Question about using functions in unrolled loop #418

Mark1626 opened this issue Feb 28, 2024 · 1 comment · Fixed by #419

Comments

@Mark1626
Copy link
Collaborator

Dahlia currently does not allow functions to be present inside loops with unrolls.

While I understand that certain kinds of functions can cause an affine violation. I want to understand why Dahlia prevents it for all functions?

Possible use-cases

Simple functions defined on Records

record complex {
    real: float;
    imag: float
}

def complex_mul(a: complex, b: complex): complex = {
    let cr: float = (a.real * b.real) - (a.imag * b.imag);
    let ci: float = (a.real * b.imag) + (a.imag * b.real);
    let c: complex = { real=cr; imag=ci };
    return c;
}

let a: complex[1024 bank 4];
let b: complex[1024 bank 4];

let c: complex[1024 bank 4];

for (let i=0..1024) unroll 4 {
  c[i] := complex_mul(a[i], a[i]);
}

Unrolling for imported functions

import vivado("math.h") {
  def cosf(v: float): float;
  def sinf(v: float): float;
}

let a: float[1024 bank 4];
let b: float[1024 bank 4];

for (let i=0..1024) unroll 4 {
  b[i] := sinf(a[i]);
}

In this case for the vivado backend during synthesis Vitis HLS generates multiple sincos units. Something similar for the Calyx backend?

@rachitnigam
Copy link
Member

Hm, interesting! Maybe the simple-to-enforce constraint here can be that if a function only has scalar inputs (like sinf), we allow it to be called in a unrolled context? The implementation should be straightforward.

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 a pull request may close this issue.

2 participants