From 2b5134f1b7f4d2ded14f138c84939d2037326c51 Mon Sep 17 00:00:00 2001 From: Mogball Date: Fri, 29 Sep 2023 18:31:12 -0700 Subject: [mlir] Fix bytecode reading of resource sections This partially reverts #66380. The assertion that the underlying buffer of an EncodingReader is aligned to any required alignments for resource sections. Resources know their own alignment and pad their buffers accordingly, but the bytecode reader doesn't know that ahead of time. Consequently, it cannot give the resource EncodingReader a base buffer aligned to the maximum required alignment. A simple example from the test fails without this: ```mlir module @TestDialectResources attributes { bytecode.test = dense_resource : tensor<4xi32> } {} {-# dialect_resources: { builtin: { resource: "0x2000000001000000020000000300000004000000", resource_2: "0x2000000001000000020000000300000004000000" } } ``` --- mlir/lib/Bytecode/Reader/BytecodeReader.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'mlir/lib/Bytecode/Reader/BytecodeReader.cpp') diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp index 98a080d..0bc2a2f 100644 --- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -111,13 +111,6 @@ public: return ((uintptr_t)ptr & (alignment - 1)) != 0; }; - // Ensure the data buffer was sufficiently aligned in the first place. - if (LLVM_UNLIKELY(isUnaligned(buffer.begin()))) { - return emitError("expected bytecode buffer to be aligned to ", alignment, - ", but got pointer: '0x" + - llvm::utohexstr((uintptr_t)buffer.begin()) + "'"); - } - // Shift the reader position to the next alignment boundary. while (isUnaligned(dataIt)) { uint8_t padding; @@ -319,7 +312,8 @@ private: // Parse in the remaining bytes of the value. llvm::support::ulittle64_t resultLE(result); - if (failed(parseBytes(numBytes, reinterpret_cast(&resultLE) + 1))) + if (failed( + parseBytes(numBytes, reinterpret_cast(&resultLE) + 1))) return failure(); // Shift out the low-order bits that were used to mark how the value was -- cgit v1.1