Skip to content

Commit 9b48f49

Browse files
j2kuncopybara-github
authored andcommitted
add splat to tensor conversion patterns
PiperOrigin-RevId: 889785595
1 parent 9ec9b61 commit 9b48f49

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

lib/Utils/ConversionUtils.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,17 @@ void addStructuralConversionPatterns(TypeConverter& typeConverter,
288288
void addTensorConversionPatterns(TypeConverter& typeConverter,
289289
RewritePatternSet& patterns,
290290
ConversionTarget& target) {
291-
patterns.add<
292-
ConvertAny<tensor::EmptyOp>, ConvertAny<tensor::InsertOp>,
293-
ConvertAny<tensor::InsertSliceOp>, ConvertAny<tensor::ExtractSliceOp>,
294-
ConvertAny<tensor::FromElementsOp>, ConvertAny<tensor::ExtractOp>>(
291+
patterns.add<ConvertAny<tensor::EmptyOp>, ConvertAny<tensor::InsertOp>,
292+
ConvertAny<tensor::InsertSliceOp>,
293+
ConvertAny<tensor::ExtractSliceOp>,
294+
ConvertAny<tensor::FromElementsOp>,
295+
ConvertAny<tensor::ExtractOp>, ConvertAny<tensor::SplatOp>>(
295296
typeConverter, patterns.getContext());
296297

297298
target.addDynamicallyLegalOp<tensor::EmptyOp, tensor::InsertOp,
298299
tensor::InsertSliceOp, tensor::ExtractOp,
299-
tensor::ExtractSliceOp, tensor::FromElementsOp>(
300+
tensor::ExtractSliceOp, tensor::FromElementsOp,
301+
tensor::SplatOp>(
300302
[&](Operation* op) { return typeConverter.isLegal(op); });
301303
}
302304

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: heir-opt --lwe-to-lattigo %s | FileCheck %s
2+
3+
#inverse_canonical_encoding = #lwe.inverse_canonical_encoding<scaling_factor = 45>
4+
#key = #lwe.key<>
5+
#modulus_chain_L1_C0 = #lwe.modulus_chain<elements = <36028797018652673 : i64, 35184372121601 : i64>, current = 0>
6+
#ring_f64_1_x1024 = #polynomial.ring<coefficientType = f64, polynomialModulus = <1 + x**1024>>
7+
!rns_L0 = !rns.rns<!mod_arith.int<36028797018652673 : i64>>
8+
#ring_rns_L0_1_x1024 = #polynomial.ring<coefficientType = !rns_L0, polynomialModulus = <1 + x**1024>>
9+
#ciphertext_space_L0 = #lwe.ciphertext_space<ring = #ring_rns_L0_1_x1024, encryption_type = mix>
10+
!ct_L0 = !lwe.lwe_ciphertext<plaintext_space = <ring = #ring_f64_1_x1024, encoding = #inverse_canonical_encoding>, ciphertext_space = #ciphertext_space_L0, key = #key, modulus_chain = #modulus_chain_L1_C0>
11+
12+
module attributes {backend.lattigo, ckks.schemeParam = #ckks.scheme_param<logN = 13, Q = [36028797018652673, 35184372121601], P = [1152921504606994433], logDefaultScale = 45, encryptionTechnique = extended>, scheme.ckks} {
13+
// CHECK: func.func @test_splat
14+
// CHECK: %[[SPLAT:.*]] = tensor.splat %{{.*}} : tensor<1x!ct>
15+
// CHECK: return %[[SPLAT]]
16+
func.func @test_splat(%ct: !ct_L0) -> tensor<1x!ct_L0> {
17+
%splat = tensor.splat %ct : tensor<1x!ct_L0>
18+
return %splat : tensor<1x!ct_L0>
19+
}
20+
}

0 commit comments

Comments
 (0)