google / google/xls

Parametric Functions: Can't call parametric function to define a parametric value.

Open
#304 3 comments 0 reactions 0 assignees View on GitHub
dslx ir
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

In the following code, the parametric value IDX_BITS is defined by calling the paramteric function std::clog2 :
```
fn dot_product(LENGTH)>
(a: bits[BITCOUNT][LENGTH], b: bits[BITCOUNT][LENGTH]) -> bits[BITCOUNT]{

for(idx, acc): (bits[IDX_BITS], bits[BITCOUNT])
in range (u32:0 , LENGTH) {

let partial_product = a[idx] * b[idx];
acc + partial_product
} (u32:0)
}

fn main(a: u32[4], b: u32[4]) -> u32 {
let result = dot_product(a, b);
u32:0
}
```
This fails to compile from dslx to ir with the following error:
```
F0217 17:13:48.770722 3 ir_converter_main.cc:135] Check failed: ::absl::OkStatus() == (status) (OK vs. INTERNAL: Not enough symbolic bindings to convert function: clog2; need {N} got {})
```
Note that we do in fact pass u32:32 to std::clog2 for the parametric value.

If we simply wrap the call to clog2 inside a nonparamteric function as below, we can successfully compile to ir:
```
fn func(a: u32) -> u32 {
std::clog2(a)
}

fn dot_product
(a: bits[BITCOUNT][LENGTH], b: bits[BITCOUNT][LENGTH]) -> bits[BITCOUNT]{

for(idx, acc): (bits[IDX_BITS], bits[BITCOUNT])
in range (u32:0 , LENGTH) {

let partial_product = a[idx] * b[idx];
acc + partial_product
} (u32:0)
}

fn main(a: u32[4], b: u32[4]) -> u32 {
let result = dot_product(a, b);
u32:0
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.