|
| 1 | +//===- LinalgInterfacesTest.cpp - LinalgInterfaces unit tests ----------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, 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/Dialect/Linalg/IR/Linalg.h" |
| 10 | +#include "mlir/Dialect/Tensor/IR/Tensor.h" |
| 11 | + |
| 12 | +#include "gtest/gtest.h" |
| 13 | + |
| 14 | +using namespace mlir; |
| 15 | + |
| 16 | +class LinalgInterfacesTest : public ::testing::Test { |
| 17 | +protected: |
| 18 | + LinalgInterfacesTest() { |
| 19 | + context.getOrLoadDialect<mlir::linalg::LinalgDialect>(); |
| 20 | + } |
| 21 | + |
| 22 | + mlir::MLIRContext context; |
| 23 | +}; |
| 24 | + |
| 25 | +TEST_F(LinalgInterfacesTest, ContractionOpOperandResultAccessor) { |
| 26 | + OpBuilder b(&context); |
| 27 | + SmallVector<int64_t> lhsShape = {1, 2}; |
| 28 | + SmallVector<int64_t> rhsShape = {2, 4}; |
| 29 | + SmallVector<int64_t> resShape = {1, 4}; |
| 30 | + auto lhs = b.create<tensor::EmptyOp>(UnknownLoc::get(&context), lhsShape, |
| 31 | + b.getF32Type()); |
| 32 | + auto rhs = b.create<tensor::EmptyOp>(UnknownLoc::get(&context), rhsShape, |
| 33 | + b.getF32Type()); |
| 34 | + auto out = b.create<tensor::EmptyOp>(UnknownLoc::get(&context), resShape, |
| 35 | + b.getF32Type()); |
| 36 | + Operation *op = b.create<linalg::MatmulOp>( |
| 37 | + UnknownLoc::get(&context), ValueRange{lhs, rhs}, ValueRange{out}); |
| 38 | + auto contractOp = llvm::cast<linalg::ContractionOpInterface>(op); |
| 39 | + |
| 40 | + EXPECT_EQ(contractOp.lhs(), op->getOperand(0)); |
| 41 | + EXPECT_EQ(contractOp.rhs(), op->getOperand(1)); |
| 42 | + EXPECT_EQ(contractOp.res(), op->getResult(0)); |
| 43 | +} |
0 commit comments