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

comb-to-cggi: fix secret cast lowerings to handle multi-dimensional tensors #810

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

copybara-service[bot]
Copy link
Contributor

comb-to-cggi: fix secret cast lowerings to handle multi-dimensional tensors

Testcase describes how this appears in the tosa-to-boolean-tfhe pipeline.

I just have to decide whether to resolve the result shapes by allocating the memref of the correct shape in the RTLIL Importer instead of expand_shape op. It doesn't matter for the opernad shapes and collapse_shape because --fold-memref-alias-ops will get rid of the load/stores from the flat tensor. But it can't "remove" the flat allocated result tensor.

@copybara-service copybara-service bot force-pushed the test_655160200 branch 3 times, most recently from 1cdba19 to 95b2d36 Compare July 24, 2024 15:15
@copybara-service copybara-service bot force-pushed the test_655160200 branch 3 times, most recently from 2a426b8 to 094743c Compare July 25, 2024 20:31
copybara-service bot pushed a commit that referenced this pull request Jul 26, 2024
…ginal result type.

In the case of yosys-optimizing a generic with a memref result type, we want to match the allocation for the result bits to match the original shape.

Before this fix, we would always allocate a flattened bit representation. For e.g. if the result shape was memref<2xi4> we would allocate memref<8xi1>. This would result in a secret.cast that was hard to handle and we couldn't fold away casting the flattened memref to the desired shape.

Instead, we allocate the memref according to the original shape. This way we can still easily fold away stores into the flattened view of the memref and casts back to the original shape.

Note that this CL is complimentary to #810 - that PR resolves the secret.cast's while this PR allows all the memref.stores generated by yosys optimizer for the result bits to be load/stored from the original desired shape. This way our final IR doesn't have any `memref.collapse_shape/expand_shape/reinterpret_cast`'s leftover.

PiperOrigin-RevId: 656418355
copybara-service bot pushed a commit that referenced this pull request Jul 26, 2024
…ginal result type.

In the case of yosys-optimizing a generic with a memref result type, we want to match the allocation for the result bits to match the original shape.

Before this fix, we would always allocate a flattened bit representation. For e.g. if the result shape was memref<2xi4> we would allocate memref<8xi1>. This would result in a secret.cast that was hard to handle and we couldn't fold away casting the flattened memref to the desired shape.

Instead, we allocate the memref according to the original shape. This way we can still easily fold away stores into the flattened view of the memref and casts back to the original shape.

Note that this CL is complimentary to #810 - that PR resolves the secret.cast's while this PR allows all the memref.stores generated by yosys optimizer for the result bits to be load/stored from the original desired shape. This way our final IR doesn't have any `memref.collapse_shape/expand_shape/reinterpret_cast`'s leftover.

PiperOrigin-RevId: 656418355
copybara-service bot pushed a commit that referenced this pull request Jul 26, 2024
…ginal result type.

In the case of yosys-optimizing a generic with a memref result type, we want to match the allocation for the result bits to match the original shape.

Before this fix, we would always allocate a flattened bit representation. For e.g. if the result shape was memref<2xi4> we would allocate memref<8xi1>. This would result in a secret.cast that was hard to handle and we couldn't fold away casting the flattened memref to the desired shape.

Instead, we allocate the memref according to the original shape. This way we can still easily fold away stores into the flattened view of the memref and casts back to the original shape.

Note that this CL is complimentary to #810 - that PR resolves the secret.cast's while this PR allows all the memref.stores generated by yosys optimizer for the result bits to be load/stored from the original desired shape. This way our final IR doesn't have any `memref.collapse_shape/expand_shape/reinterpret_cast`'s leftover.

PiperOrigin-RevId: 656418355
copybara-service bot pushed a commit that referenced this pull request Jul 26, 2024
…ginal result type.

In the case of yosys-optimizing a generic with a memref result type, we want to match the allocation for the result bits to match the original shape.

Before this fix, we would always allocate a flattened bit representation. For e.g. if the result shape was memref<2xi4> we would allocate memref<8xi1>. This would result in a secret.cast that was hard to handle and we couldn't fold away casting the flattened memref to the desired shape.

Instead, we allocate the memref according to the original shape. This way we can still easily fold away stores into the flattened view of the memref and casts back to the original shape.

Note that this CL is complimentary to #810 - that PR resolves the secret.cast's while this PR allows all the memref.stores generated by yosys optimizer for the result bits to be load/stored from the original desired shape. This way our final IR doesn't have any `memref.collapse_shape/expand_shape/reinterpret_cast`'s leftover.

PiperOrigin-RevId: 656418355
@copybara-service copybara-service bot force-pushed the test_655160200 branch 2 times, most recently from e704e26 to d055a2c Compare July 29, 2024 20:17
…ensors

Testcase describes how this appears in the tosa-to-boolean-tfhe pipeline.

I just have to decide whether to resolve the result shapes by allocating the memref of the correct shape in the RTLIL Importer instead of expand_shape op. It doesn't matter for the opernad shapes and collapse_shape because --fold-memref-alias-ops will get rid of the load/stores from the flat tensor. But it can't "remove" the flat allocated result tensor.

PiperOrigin-RevId: 657307963
@copybara-service copybara-service bot merged commit 172275e into main Jul 29, 2024
@copybara-service copybara-service bot deleted the test_655160200 branch July 29, 2024 20:31
copybara-service bot pushed a commit that referenced this pull request Jul 30, 2024
…ginal result type.

In the case of yosys-optimizing a generic with a memref result type, we want to match the allocation for the result bits to match the original shape.

Before this fix, we would always allocate a flattened bit representation. For e.g. if the result shape was memref<2xi4> we would allocate memref<8xi1>. This would result in a secret.cast that was hard to handle and we couldn't fold away casting the flattened memref to the desired shape.

Instead, we allocate the memref according to the original shape. This way we can still easily fold away stores into the flattened view of the memref and casts back to the original shape.

Note that this CL is complimentary to #810 - that PR resolves the secret.cast's while this PR allows all the memref.stores generated by yosys optimizer for the result bits to be load/stored from the original desired shape. This way our final IR doesn't have any `memref.collapse_shape/expand_shape/reinterpret_cast`'s leftover.

PiperOrigin-RevId: 656418355
copybara-service bot pushed a commit that referenced this pull request Jul 31, 2024
…ginal result type.

In the case of yosys-optimizing a generic with a memref result type, we want to match the allocation for the result bits to match the original shape.

Before this fix, we would always allocate a flattened bit representation. For e.g. if the result shape was memref<2xi4> we would allocate memref<8xi1>. This would result in a secret.cast that was hard to handle and we couldn't fold away casting the flattened memref to the desired shape.

Instead, we allocate the memref according to the original shape. This way we can still easily fold away stores into the flattened view of the memref and casts back to the original shape.

Note that this CL is complimentary to #810 - that PR resolves the secret.cast's while this PR allows all the memref.stores generated by yosys optimizer for the result bits to be load/stored from the original desired shape. This way our final IR doesn't have any `memref.collapse_shape/expand_shape/reinterpret_cast`'s leftover.

PiperOrigin-RevId: 656418355
copybara-service bot pushed a commit that referenced this pull request Jul 31, 2024
…ginal result type.

In the case of yosys-optimizing a generic with a memref result type, we want to match the allocation for the result bits to match the original shape.

Before this fix, we would always allocate a flattened bit representation. For e.g. if the result shape was memref<2xi4> we would allocate memref<8xi1>. This would result in a secret.cast that was hard to handle and we couldn't fold away casting the flattened memref to the desired shape.

Instead, we allocate the memref according to the original shape. This way we can still easily fold away stores into the flattened view of the memref and casts back to the original shape.

Note that this CL is complimentary to #810 - that PR resolves the secret.cast's while this PR allows all the memref.stores generated by yosys optimizer for the result bits to be load/stored from the original desired shape. This way our final IR doesn't have any `memref.collapse_shape/expand_shape/reinterpret_cast`'s leftover.

PiperOrigin-RevId: 656418355
copybara-service bot pushed a commit that referenced this pull request Jul 31, 2024
…ginal result type.

In the case of yosys-optimizing a generic with a memref result type, we want to match the allocation for the result bits to match the original shape.

Before this fix, we would always allocate a flattened bit representation. For e.g. if the result shape was memref<2xi4> we would allocate memref<8xi1>. This would result in a secret.cast that was hard to handle and we couldn't fold away casting the flattened memref to the desired shape.

Instead, we allocate the memref according to the original shape. This way we can still easily fold away stores into the flattened view of the memref and casts back to the original shape.

Note that this CL is complimentary to #810 - that PR resolves the secret.cast's while this PR allows all the memref.stores generated by yosys optimizer for the result bits to be load/stored from the original desired shape. This way our final IR doesn't have any `memref.collapse_shape/expand_shape/reinterpret_cast`'s leftover.

PiperOrigin-RevId: 658128669
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.

2 participants