Skip to content
Merged
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
10 changes: 4 additions & 6 deletions mlir/include/mlir/ExecutionEngine/MemRefUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,17 @@ class OwningMemRef {
int64_t nElements = 1;
for (int64_t s : shapeAlloc)
nElements *= s;
auto [data, alignedData] =
auto [allocatedPtr, alignedData] =
detail::allocAligned<T>(nElements, allocFun, alignment);
descriptor = detail::makeStridedMemRefDescriptor<Rank>(data, alignedData,
shape, shapeAlloc);
descriptor = detail::makeStridedMemRefDescriptor<Rank>(
allocatedPtr, alignedData, shape, shapeAlloc);
if (init) {
for (StridedMemrefIterator<T, Rank> it = descriptor.begin(),
end = descriptor.end();
it != end; ++it)
init(*it, it.getIndices());
} else {
memset(descriptor.data, 0,
nElements * sizeof(T) +
alignment.value_or(detail::nextPowerOf2(sizeof(T))));
memset(alignedData, 0, nElements * sizeof(T));
}
}
/// Take ownership of an existing descriptor with a custom deleter.
Expand Down
18 changes: 18 additions & 0 deletions mlir/unittests/ExecutionEngine/Invoke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,24 @@ TEST(NativeMemRefJit, SKIP_WITHOUT_JIT(BasicMemref)) {
EXPECT_EQ((a[{2, 1}]), 42.);
}

TEST(NativeMemRefJit, SKIP_WITHOUT_JIT(OwningMemrefZeroInit)) {
constexpr int k = 3;
constexpr int m = 7;
int64_t shape[] = {k, m};
// Use a large alignment to stress the case where the memref data/basePtr are
// disjoint.
int alignment = 8192;
OwningMemRef<float, 2> a(shape, {}, {}, alignment);
ASSERT_EQ(
(void *)(((uintptr_t)a->basePtr + alignment - 1) & ~(alignment - 1)),
a->data);
for (int i = 0; i < k; ++i) {
for (int j = 0; j < m; ++j) {
EXPECT_EQ((a[{i, j}]), 0.);
}
}
}

// A helper function that will be called from the JIT
static void memrefMultiply(::StridedMemRefType<float, 2> *memref,
int32_t coefficient) {
Expand Down