1//===- StridedMemRef.cpp ----------------------------------------*- C++ -*-===//
2//
3// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "mlir/ExecutionEngine/CRunnerUtils.h"
10#include "llvm/ADT/SmallVector.h"
11
12#include "gmock/gmock.h"
13
14using namespace ::mlir;
15using namespace ::testing;
16
17TEST(StridedMemRef, rankOneWithOffset) {
18 std::array<int, 15> data;
19
20 for (size_t i = 0; i < data.size(); ++i) {
21 data[i] = i;
22 }
23
24 StridedMemRefType<int, 1> memRefA;
25 memRefA.basePtr = data.data();
26 memRefA.data = data.data();
27 memRefA.offset = 0;
28 memRefA.sizes[0] = 10;
29 memRefA.strides[0] = 1;
30
31 StridedMemRefType<int, 1> memRefB = memRefA;
32 memRefB.offset = 5;
33
34 llvm::SmallVector<int, 10> valuesA(memRefA.begin(), memRefA.end());
35 llvm::SmallVector<int, 10> valuesB(memRefB.begin(), memRefB.end());
36
37 for (int64_t i = 0; i < 10; ++i) {
38 EXPECT_EQ(valuesA[i], i);
39 EXPECT_EQ(valuesA[i] + 5, valuesB[i]);
40 }
41}
42

source code of mlir/unittests/ExecutionEngine/StridedMemRef.cpp