Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

remove aie to txn from aie-translate and python biding #5

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
4 changes: 0 additions & 4 deletions include/aie-c/Translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ MLIR_CAPI_EXPORTED MlirLogicalResult
aieTranslateToCDODirect(MlirOperation moduleOp, MlirStringRef workDirPath,
bool bigEndian, bool emitUnified, bool cdoDebug,
bool aieSim, bool xaieDebug, bool enableCores);

MLIR_CAPI_EXPORTED MlirLogicalResult aieTranslateToTxn(
MlirOperation moduleOp, MlirStringRef outputFile, MlirStringRef workDirPath,
bool aieSim, bool xaieDebug, bool enableCores);
MLIR_CAPI_EXPORTED MlirLogicalResult aieTranslateToCtrlpkt(
MlirOperation moduleOp, MlirStringRef outputFile, MlirStringRef workDirPath,
bool aieSim, bool xaieDebug, bool enableCores);
Expand Down
32 changes: 32 additions & 0 deletions include/aie/Conversion/AIEToConfiguration/AIEToConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===- AIEToConfiguration.h -------------------------------------*- C++ -*-===//
//
// 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
//
// Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.
//
//===----------------------------------------------------------------------===//

#ifndef AIE_CONVERSION_AIETOCONFIGURATION_AIETOCONFIGURATION_H
#define AIE_CONVERSION_AIETOCONFIGURATION_AIETOCONFIGURATION_H

#include "aie/Dialect/AIE/IR/AIEDialect.h"
#include "aie/Dialect/AIEX/IR/AIEXDialect.h"

#include "mlir/Pass/Pass.h"

#include <memory>

namespace xilinx::AIE {

std::unique_ptr<mlir::OperationPass<xilinx::AIE::DeviceOp>>
createConvertAIEToTransactionPass();

std::optional<mlir::ModuleOp>
convertTransactionBinaryToMLIR(mlir::MLIRContext *ctx,
std::vector<uint8_t> &binary);

} // namespace xilinx::AIE

#endif // AIE_CONVERSION_AIETOCONFIGURATION_AIETOCONFIGURATION_H
5 changes: 5 additions & 0 deletions include/aie/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 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 2024 Advanced Micro Devices, Inc.
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Conversion)
mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header -prefix Conversion)
Expand Down
1 change: 1 addition & 0 deletions include/aie/Conversion/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#ifndef AIE_CONVERSION_PASSES_H
#define AIE_CONVERSION_PASSES_H

#include "aie/Conversion/AIEToConfiguration/AIEToConfiguration.h"
#include "aie/Conversion/AIEVecToLLVM/AIEVecToLLVM.h"
#include "aie/Conversion/PassesEnums.h.inc"

Expand Down
24 changes: 24 additions & 0 deletions include/aie/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,28 @@ def ConvertAIEVecToLLVM : Pass<"convert-aievec-to-llvm", "mlir::ModuleOp"> {
];
}

//===----------------------------------------------------------------------===//
// AIEToTransaction
//===----------------------------------------------------------------------===//

def ConvertAIEToTransaction : Pass<"convert-aie-to-transaction",
"xilinx::AIE::DeviceOp"> {
let summary = "Convert AIE dialect to npu transaction operations";
let description = [{
This pass converts aie.device operations to a sequence of transaction binary
operations (writes, masked writes, and block writes) that can be used to
to configure the npu device. The transaction operations are emitted as
`npu.write32`, `npu.maskwrite32`, and `npu.blockwrite` operations. A new
`aiex.runtime_sequence` operation is inserted into the `aie.device` to
contain the new transaction operations sequence.
}];
let constructor = "xilinx::AIE::createConvertAIEToTransactionPass()";
let dependentDialects = ["xilinx::AIE::AIEDialect",
"xilinx::AIEX::AIEXDialect"];
let options = [
Option<"clElfDir", "elf-dir", "std::string", /*default=*/"",
"Where to find ELF files">,
];
}

#endif // AIE_CONVERSION_PASSES
2 changes: 1 addition & 1 deletion include/aie/Dialect/AIEX/Transforms/AIEXPasses.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- AIEPasses.h ----------------------------------------------*- C++ -*-===//
//===- AIEXPasses.h ---------------------------------------------*- C++ -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
20 changes: 8 additions & 12 deletions include/aie/Targets/AIETargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ mlir::LogicalResult AIETranslateShimSolution(mlir::ModuleOp module,
mlir::LogicalResult AIETranslateGraphXPE(mlir::ModuleOp module,
llvm::raw_ostream &);
mlir::LogicalResult AIETranslateToNPU(mlir::ModuleOp module,
llvm::raw_ostream &output);
mlir::LogicalResult AIETranslateToNPU(mlir::ModuleOp, std::vector<uint32_t> &);
llvm::raw_ostream &output,
llvm::StringRef sequenceName = "");
mlir::LogicalResult AIETranslateToNPU(mlir::ModuleOp, std::vector<uint32_t> &,
llvm::StringRef sequenceName = "");
mlir::LogicalResult
AIETranslateControlPacketsToUI32Vec(mlir::ModuleOp module,
llvm::raw_ostream &output);
llvm::raw_ostream &output,
llvm::StringRef sequenceName = "");
mlir::LogicalResult
AIETranslateControlPacketsToUI32Vec(mlir::ModuleOp, std::vector<uint32_t> &);
AIETranslateControlPacketsToUI32Vec(mlir::ModuleOp, std::vector<uint32_t> &,
llvm::StringRef sequenceName = "");
mlir::LogicalResult AIETranslateToLdScript(mlir::ModuleOp module,
llvm::raw_ostream &output,
int tileCol, int tileRow);
Expand All @@ -60,11 +64,6 @@ AIETranslateToCDODirect(mlir::ModuleOp m, llvm::StringRef workDirPath,
bool cdoDebug = false, bool aieSim = false,
bool xaieDebug = false, bool enableCores = true);
mlir::LogicalResult
AIETranslateToTxn(mlir::ModuleOp m, llvm::raw_ostream &output,
llvm::StringRef workDirPath, bool outputBinary = false,
bool aieSim = false, bool xaieDebug = false,
bool enableCores = true);
mlir::LogicalResult
AIETranslateToControlPackets(mlir::ModuleOp m, llvm::raw_ostream &output,
llvm::StringRef workDirPath,
bool outputBinary = false, bool aieSim = false,
Expand All @@ -80,9 +79,6 @@ mlir::LogicalResult AIETranslateToAirbin(mlir::ModuleOp module,
mlir::LogicalResult AIETranslateToTargetArch(mlir::ModuleOp module,
llvm::raw_ostream &output);

std::optional<mlir::ModuleOp>
AIETranslateBinaryToTxn(mlir::MLIRContext *ctx, std::vector<uint8_t> &binary);

std::optional<mlir::ModuleOp>
AIETranslateBinaryToCtrlpkt(mlir::MLIRContext *ctx,
std::vector<uint8_t> &binary);
Expand Down
1 change: 1 addition & 0 deletions lib/CAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_mlir_public_c_api_library(AIECAPI
AIEX
AIEXTransforms
AIEXUtils
MLIRAIEToConfiguration
MLIRAIEVecDialect
MLIRAIEVecAIE1Dialect
MLIRAIEVecToLLVM
Expand Down
36 changes: 2 additions & 34 deletions lib/CAPI/Translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "aie-c/Translation.h"

#include "aie/Conversion/AIEToConfiguration/AIEToConfiguration.h"
#include "aie/Dialect/AIE/IR/AIETargetModel.h"
#include "aie/Targets/AIERT.h"
#include "aie/Targets/AIETargets.h"
Expand Down Expand Up @@ -83,39 +84,6 @@ MlirLogicalResult aieTranslateToCDODirect(MlirOperation moduleOp,
return wrap(status);
}

MlirLogicalResult aieTranslateToTxn(MlirOperation moduleOp,
MlirStringRef outputFile,
MlirStringRef workDirPath, bool aieSim,
bool xaieDebug, bool enableCores) {
ModuleOp mod = llvm::cast<ModuleOp>(unwrap(moduleOp));
bool outputBinary = false;

std::string errorMessage;
auto output = openOutputFile(StringRef(outputFile.data, outputFile.length),
&errorMessage);
if (!output) {
llvm::errs() << errorMessage << "\n";
return wrap(failure());
}

auto status = AIETranslateToTxn(
mod, output->os(), llvm::StringRef(workDirPath.data, workDirPath.length),
outputBinary, aieSim, xaieDebug, enableCores);

std::vector<std::string> diagnostics;
ScopedDiagnosticHandler handler(mod.getContext(), [&](Diagnostic &d) {
llvm::raw_string_ostream(diagnostics.emplace_back())
<< d.getLocation() << ": " << d;
});

if (failed(status))
for (const auto &diagnostic : diagnostics)
std::cerr << diagnostic << "\n";
else
output->keep();
return wrap(status);
}

MlirLogicalResult aieTranslateToCtrlpkt(MlirOperation moduleOp,
MlirStringRef outputFile,
MlirStringRef workDirPath, bool aieSim,
Expand Down Expand Up @@ -151,7 +119,7 @@ MlirLogicalResult aieTranslateToCtrlpkt(MlirOperation moduleOp,

MlirOperation aieTranslateBinaryToTxn(MlirContext ctx, MlirStringRef binary) {
std::vector<uint8_t> binaryData(binary.data, binary.data + binary.length);
auto mod = AIETranslateBinaryToTxn(unwrap(ctx), binaryData);
auto mod = convertTransactionBinaryToMLIR(unwrap(ctx), binaryData);
if (!mod)
return wrap(ModuleOp().getOperation());
return wrap(mod->getOperation());
Expand Down
Loading