Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Target/OpenFhePke/OpenFhePkeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1692,8 +1692,12 @@ LogicalResult OpenFhePkeEmitter::printOperation(tensor::SplatOp op) {
LogicalResult OpenFhePkeEmitter::printOperation(tensor::FromElementsOp op) {
// std::vector<CiphertextType> result = {input[0], ..., input[n]};
auto result = op.getResult();
if (result.getType().getRank() != 1) {
return failure();
// Only rank-0 and rank-1 tensor construction is currently supported.
// TODO(#1703): Support higher-rank tensors.
Comment on lines +1695 to +1696

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Technically true, but I don't think we will see many natural workflows that produce a from_elements that produces a rank-2+ tensor.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, it’s unlikely to come up. The error is mainly so it fails clearly rather than emitting invalid code. Happy to drop the TODO (and #1703) if you’d rather not track it.

if (result.getType().getRank() > 1) {
return op.emitOpError()
<< "expected a rank-0 or rank-1 tensor, but got rank "
<< result.getType().getRank();
}
os << "const ";
if (failed(emitTypedAssignPrefix(result, op->getLoc()))) {
Expand Down
8 changes: 8 additions & 0 deletions tests/Emitter/Openfhe/emit_0d_tensor.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ module attributes {scheme.bgv} {
%0 = tensor.insert %v into %arg0[] : tensor<f32>
return %0 : tensor<f32>
}

func.func @test_0d_tensor_from_elements(%arg0: f32) -> tensor<f32> {
// CHECK: std::vector<float> test_0d_tensor_from_elements(float [[arg0:[^ ]*]])
// CHECK: const std::vector<float> [[result:[^ ]*]] = {[[arg0]]};
// CHECK: return [[result]];
%0 = tensor.from_elements %arg0 : tensor<f32>
return %0 : tensor<f32>
}
}
9 changes: 9 additions & 0 deletions tests/Emitter/Openfhe/emit_2d_tensor_error.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: not heir-translate %s --emit-openfhe-pke 2>&1 | FileCheck %s

module attributes {scheme.bgv} {
func.func @test_2d_tensor_from_elements(%arg0: f32) -> tensor<1x1xf32> {
// CHECK: 'tensor.from_elements' op expected a rank-0 or rank-1 tensor, but got rank 2
%0 = tensor.from_elements %arg0 : tensor<1x1xf32>
return %0 : tensor<1x1xf32>
}
}
Loading