Skip to content

[spec] Add dtype and layout arguments to ttl.block.fill#611

Open
phizalev-TT wants to merge 6 commits into
mainfrom
phizalev/spec-ttl-block-fill-dtype-arg
Open

[spec] Add dtype and layout arguments to ttl.block.fill#611
phizalev-TT wants to merge 6 commits into
mainfrom
phizalev/spec-ttl-block-fill-dtype-arg

Conversation

@phizalev-TT
Copy link
Copy Markdown
Contributor

No description provided.

| Function | Description |
| :---- | :---- |
| `ttl.block.fill(value: float, shape: ttl.Shape) -> ttl.BlockExpr` | Fill a block of specified `shape` with specified `value`. |
| `ttl.block.fill(value: float, dtype: ttnn.DataType, shape: ttl.Shape) -> ttl.BlockExpr` | Fill a block of specified `shape` with specified `value` of specified `dtype`. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a change in the signature of fill and it is not an optional argument, I expect all instances of fill will have to be changed throughout this document?

Copy link
Copy Markdown
Contributor

@brnorris03 brnorris03 May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's true -- and not just the document, but examples, too; I can do that in the still-open #599 -- or you @FConstantinos feel free to commit sim changes there directly (if we agree to merge the spec change first before 599 lands).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, 599 is already too big, so ignore the above. We can just do the dtype addition separately in subsequent PRs. I'll have to change the compiler's fill implementation anyway since currently dtype is optional (and last).

@vtsilytskyiTT
Copy link
Copy Markdown
Contributor

This feels like a language gap. value is always float and we separately pass the type to cast to.
In perfect case fill should accept various value types and rely on that type.
Do we use something like ttnn.DataType(0) as the first argument?

@brnorris03
Copy link
Copy Markdown
Contributor

This feels like a language gap. value is always float and we separately pass the type to cast to. In perfect case fill should accept various value types and rely on that type. Do we use something like ttnn.DataType(0) as the first argument?

I think the problem is that there is no concise way to create a correctly-typed constant host scalar in Python. Users would have to call something like fill(val = ttnn.full([], 0.5, dtype=ttnn.bfloat16), shape=some_shape). I think that's much more awkward and less clean than a simple dtype arg, but that's just my opinion. The compiler will be able support any valid python scalar without a dtype arg eventually (so just float val and shape args) after type inference is implemented.

@FConstantinos
Copy link
Copy Markdown
Contributor

Do we want to add a version row?

@FConstantinos
Copy link
Copy Markdown
Contributor

re value: float no problem with that, but are we sure we won't support types with greater than 32 bit floats?

I also understand that we never deal with tensors of integers, is that accurate?

@FConstantinos
Copy link
Copy Markdown
Contributor

Also, should we consider a default for dtype? (e.g float32) or do we need to make this non-optional?

| Function | Description |
| :---- | :---- |
| `ttl.block.fill(value: float, shape: ttl.Shape) -> ttl.BlockExpr` | Fill a block of specified `shape` with specified `value`. |
| `ttl.block.fill(value: float, dtype: ttnn.DataType, shape: ttl.Shape) -> ttl.BlockExpr` | Fill a block of specified `shape` with specified `value` of specified `dtype`. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is ttnn.DataType defined anywhere?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the spec needs to define ttnn entities, that's up to the ttnn docs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We rely on ttnn.Tensor in the same way. It is defined by TT=NN.

| Function | Description |
| :---- | :---- |
| `ttl.block.fill(value: float, shape: ttl.Shape) -> ttl.BlockExpr` | Fill a block of specified `shape` with specified `value`. |
| `ttl.block.fill(value: float, dtype: ttnn.DataType, shape: ttl.Shape) -> ttl.BlockExpr` | Fill a block of specified `shape` with specified `value` of specified `dtype`. |
Copy link
Copy Markdown
Contributor

@FConstantinos FConstantinos May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess an important question is, how do we know the layout of the fill (TILE_LAYOUT vs ROW_MAJOR_LAYOUT)? Perhaps we need to add more arguments that specify this? Or perhaps say that fill always produces a tiled block?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sim supports multiple layouts, so this does seem necessary, perhaps make it an optional arg with a default TILE_LAYOUT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should be good

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

@brnorris03
Copy link
Copy Markdown
Contributor

Also, should we consider a default for dtype? (e.g float32) or do we need to make this non-optional?

I also think optional with some reasonable default is good. I think bf16 is WAY more common though (and f32 has quite a few bugs in the llks, hardware), so I think having it be the default doesn't actually help the compiler much since that means we have to explicitly have dtype=ttnn.bf16 in most of the code.

@phizalev-TT
Copy link
Copy Markdown
Contributor Author

re value: float no problem with that, but are we sure we won't support types with greater than 32 bit floats?

I also understand that we never deal with tensors of integers, is that accurate?

We can create integer by using corresponding dtype, which will truncate float constant. Same goes for any other type.

@phizalev-TT
Copy link
Copy Markdown
Contributor Author

Do we want to add a version row?

This is minor change and with default dtype is fully backward compatible, so no version.

@phizalev-TT phizalev-TT changed the title [spec] Add dtype argument to ttl.block.fill [spec] Add dtype and layout arguments to ttl.block.fill May 21, 2026
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.

4 participants