Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

POC for Buffer Descriptor Analysis #569

Closed
wants to merge 3 commits into from
Closed
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
90 changes: 90 additions & 0 deletions include/aie/Analysis/BufferDescriptorAnalysis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//===- BufferDescriptorAnalysis.h -----------------------------------------===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// (c) Copyright 2023 Xilinx Inc.
//
//===----------------------------------------------------------------------===//

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? Is it really specific to your target, or is it more general?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more to the target. Any suggestion on where this header file should live?

#ifndef MLIR_AIE_ANALYSIS_BUFFERDESCRIPTORANALYSIS_H
#define MLIR_AIE_ANALYSIS_BUFFERDESCRIPTORANALYSIS_H

#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/BuiltinOps.h"

#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
#include <iostream>

using namespace mlir;

namespace xilinx {
namespace AIE {

struct BufferDescriptorState {
public:
BufferDescriptorState() = default;

int64_t getTotalLengthInt() const {
int64_t ret = 1;
for (auto len : lengthInt) {
ret *= len;
}
return ret;
}

void print(raw_ostream &os) const;
void printInt(raw_ostream &os) const;

public:
SmallVector<int64_t, 4> lengthInt;
Value baseVal;
SmallVector<int64_t, 4> stepsInt;
SmallVector<int64_t, 4> wrapsInt;

SmallVector<OpFoldResult> length;
OpFoldResult base;
SmallVector<OpFoldResult> steps;
SmallVector<OpFoldResult> wraps;

std::optional<int64_t> repetition;
std::optional<int64_t> constantStep;

Value source;
};

class BufferDescriptorAnalysis {
public:
BufferDescriptorAnalysis() = default;

static void visitOperand(Value operand, BufferDescriptorState &state);

static void visitOperandReintCast(memref::ReinterpretCastOp reintCastOp,
BufferDescriptorState &state);

static void visitOperandSubView(memref::SubViewOp subViewOp,
BufferDescriptorState &state);

static void visitOperandCopy(memref::CopyOp copyOp,
BufferDescriptorState &state);

static void visitOperandTensorStore(memref::TensorStoreOp tensorStoreOp,
BufferDescriptorState &state);

static void visitOperandCast(memref::CastOp castOp,
BufferDescriptorState &state);
};

} // namespace AIE
} // namespace xilinx

#endif
14 changes: 12 additions & 2 deletions lib/Targets/AIETargets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include "aie/Dialect/ADF/ADFDialect.h"
#include "aie/Dialect/AIE/AIENetlistAnalysis.h"
#include "aie/Dialect/AIE/IR/AIEDialect.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"

using namespace mlir;
using namespace mlir::vector;
Expand Down Expand Up @@ -549,6 +547,18 @@ SECTIONS
"aie-mlir-to-shim-solution",
"Translate AIE design to ShimSolution file for simulation",
AIETranslateShimSolution, registerDialects);
TranslateFromMLIRRegistration registrationLinAlgToADF(
"linalg-to-adf", "Translate LinAlg dialect to C++ ADF graph (POC)",
[](ModuleOp module, raw_ostream &output) {
return TranslateLinalgToADF(module, output);
},
[](DialectRegistry &registry) {
registry.insert<arith::ArithDialect, linalg::LinalgDialect,
bufferization::BufferizationDialect, LLVM::LLVMDialect,
math::MathDialect, memref::MemRefDialect,
func::FuncDialect, tensor::TensorDialect,
cf::ControlFlowDialect, scf::SCFDialect>();
});
}
} // namespace AIE
} // namespace xilinx
8 changes: 8 additions & 0 deletions lib/Targets/AIETargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
//
//===----------------------------------------------------------------------===//

#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Support/LogicalResult.h"
#include "llvm/Support/raw_ostream.h"
Expand All @@ -26,5 +32,7 @@ mlir::LogicalResult AIETranslateShimSolution(mlir::ModuleOp module,
llvm::raw_ostream &);
mlir::LogicalResult AIETranslateGraphXPE(mlir::ModuleOp module,
llvm::raw_ostream &);
mlir::LogicalResult TranslateLinalgToADF(mlir::ModuleOp module,
llvm::raw_ostream &output);
}
}
Loading