From 1a01493af24471e0c1f96bad2834067896109e7d Mon Sep 17 00:00:00 2001 From: Alexander Viand Date: Thu, 28 May 2026 10:25:52 +0200 Subject: [PATCH] support DenseResourceElementsAttr in memref'ed lattigo emitter --- lib/Target/Lattigo/LattigoEmitter.cpp | 5 +++++ tests/Emitter/Lattigo/memref.mlir | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Target/Lattigo/LattigoEmitter.cpp b/lib/Target/Lattigo/LattigoEmitter.cpp index e20757e3dc..892c44d451 100644 --- a/lib/Target/Lattigo/LattigoEmitter.cpp +++ b/lib/Target/Lattigo/LattigoEmitter.cpp @@ -1112,6 +1112,11 @@ LogicalResult LattigoEmitter::printOperation(memref::GlobalOp op) { return op.emitError("memref.global must have an initial value"); } + if (auto resourceAttr = dyn_cast(initAttr)) { + initAttr = DenseElementsAttr::getFromRawBuffer(resourceAttr.getType(), + resourceAttr.getData()); + } + if (auto denseAttr = dyn_cast(initAttr)) { if (denseAttr.isSplat()) { imports.insert(std::string(kSlicesImport)); diff --git a/tests/Emitter/Lattigo/memref.mlir b/tests/Emitter/Lattigo/memref.mlir index 8c00fc9b51..e0b87b0da7 100644 --- a/tests/Emitter/Lattigo/memref.mlir +++ b/tests/Emitter/Lattigo/memref.mlir @@ -4,6 +4,9 @@ module attributes {backend.lattigo, scheme.ckks} { memref.global "private" constant @__constant_1024xf32 : memref<1024xf32> = dense<1.000000e+00> +// CHECK: var __constant_4xi32 = []int32{1, 2, 3, 4} +memref.global "private" constant @__constant_4xi32 : memref<4xi32> = dense_resource + // CHECK: func test_memref(_ []float32) ([]float32, int64) { func.func @test_memref(%arg0: memref<1024xf32>) -> (memref<1024xf32>, index) { %c0 = arith.constant 0 : index @@ -48,6 +51,12 @@ func.func @test_shape(%arg0: memref<1024xf32>) -> memref<1024xf32> { return %collapse : memref<1024xf32> } - - } + +{-# + dialect_resources: { + builtin: { + weights: "0x4000000001000000020000000300000004000000" + } + } +#-}