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

Add hasProperty method to targetModel #1929

Merged
merged 13 commits into from
Nov 22, 2024
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
50 changes: 32 additions & 18 deletions include/aie/Dialect/AIE/IR/AIETargetModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ class AIETargetModel {
TK_AIE2_Last = TK_AIE2_NPU2_Last,
};

// One-hot encoded list of target model properties.
enum ModelProperty {
// Device uses semaphore locks.
UsesSemaphoreLocks = 1U << 0,
// Device is an NPU-based device.
// There are several special cases for handling the NPU at the moment.
IsNPU = 1U << 1,
// Device model is virtualized.
// This is used during CDO code generation to configure aie-rt properly.
IsVirtualized = 1U << 2,
// Device uses multi-dimensional buffer descriptors.
UsesMultiDimensionalBDs = 1U << 3,
};

private:
const TargetModelKind kind;

Expand Down Expand Up @@ -232,9 +246,11 @@ class AIETargetModel {
// Run consistency checks on the target model.
void validate() const;

// Return true if this is an NPU-based device
// There are several special cases for handling the NPU at the moment.
virtual bool isNPU() const { return false; }
// Return true if this device has a given property.
uint32_t ModelProperties = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be private

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Let me fix this in a separate PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PR created: #1944

bool hasProperty(ModelProperty Prop) const {
return (ModelProperties & Prop) == Prop;
}

// Return the bit offset of the column within a tile address.
// This is used to compute the control address of a tile from it's column
Expand Down Expand Up @@ -318,7 +334,11 @@ class AIE1TargetModel : public AIETargetModel {

class AIE2TargetModel : public AIETargetModel {
public:
AIE2TargetModel(TargetModelKind k) : AIETargetModel(k) {}
AIE2TargetModel(TargetModelKind k) : AIETargetModel(k) {
// Device properties initialization
ModelProperties |= AIETargetModel::UsesSemaphoreLocks;
ModelProperties |= AIETargetModel::UsesMultiDimensionalBDs;
}

AIEArch getTargetArch() const override;

Expand Down Expand Up @@ -502,7 +522,10 @@ class VE2802TargetModel : public AIE2TargetModel {

class BaseNPUTargetModel : public AIE2TargetModel {
public:
BaseNPUTargetModel(TargetModelKind k) : AIE2TargetModel(k) {}
BaseNPUTargetModel(TargetModelKind k) : AIE2TargetModel(k) {
// Device properties initialization
ModelProperties |= AIETargetModel::IsNPU;
}

int rows() const override {
return 6; /* 1 Shim row, 1 memtile row, and 4 Core rows. */
Expand All @@ -521,12 +544,6 @@ class BaseNPUTargetModel : public AIE2TargetModel {

uint32_t getNumMemTileRows() const override { return 1; }

// Return true if the device model is virtualized. This is used
// during CDO code generation to configure aie-rt properly.
virtual bool isVirtualized() const = 0;

virtual bool isNPU() const override { return true; }

static bool classof(const AIETargetModel *model) {
return model->getKind() >= TK_AIE2_NPU1 &&
model->getKind() < TK_AIE2_NPU2_Last;
Expand All @@ -549,8 +566,6 @@ class NPUTargetModel : public BaseNPUTargetModel {
return row == 0 && col == 0;
}

bool isVirtualized() const override { return false; }

static bool classof(const AIETargetModel *model) {
return model->getKind() == TK_AIE2_NPU1;
}
Expand All @@ -565,16 +580,17 @@ class VirtualizedNPUTargetModel : public BaseNPUTargetModel {
: BaseNPUTargetModel(static_cast<TargetModelKind>(
static_cast<std::underlying_type_t<TargetModelKind>>(TK_AIE2_NPU1) +
_cols)),
cols(_cols) {}
cols(_cols) {
// Device properties initialization
ModelProperties |= AIETargetModel::IsVirtualized;
}

uint32_t getAddressGenGranularity() const override { return 32; }

int columns() const override { return cols; }

bool isShimNOCTile(int col, int row) const override { return row == 0; }

bool isVirtualized() const override { return true; }

static bool classof(const AIETargetModel *model) {
return model->getKind() >= TK_AIE2_NPU1_1Col &&
model->getKind() < TK_AIE2_NPU1_Last;
Expand All @@ -594,8 +610,6 @@ class NPU2TargetModel : public BaseNPUTargetModel {

bool isShimPLTile(int col, int row) const override { return false; }

bool isVirtualized() const override { return false; }

static bool classof(const AIETargetModel *model) {
return model->getKind() == TK_AIE2_NPU2;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/CAPI/TargetModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ uint32_t aieTargetModelGetNumBanks(AieTargetModel targetModel, int col,
}

bool aieTargetModelIsNPU(AieTargetModel targetModel) {
return unwrap(targetModel).isNPU();
return unwrap(targetModel).hasProperty(xilinx::AIE::AIETargetModel::IsNPU);
}

uint32_t aieTargetModelGetColumnShift(AieTargetModel targetModel) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Conversion/AIEToConfiguration/AIEToConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ static LogicalResult convertAIEToConfiguration(AIE::DeviceOp device,
const BaseNPUTargetModel &targetModel =
(const BaseNPUTargetModel &)device.getTargetModel();

if (!targetModel.isNPU())
if (!targetModel.hasProperty(AIETargetModel::IsNPU))
return failure();

bool aieSim = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ struct AIEObjectFifoStatefulTransformPass
target = objFifoLinks[*linkOp];

auto dev = op->getParentOfType<DeviceOp>();
if (isa<AIE1TargetModel>(dev.getTargetModel())) {
if (!dev.getTargetModel().hasProperty(AIETargetModel::UsesSemaphoreLocks)) {

if (locksPerFifo[target].size() == 0) {
for (int i = 0; i < numLocks; i++) {
Expand Down
6 changes: 4 additions & 2 deletions lib/Targets/AIERT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ AIERTControl::AIERTControl(const AIE::BaseNPUTargetModel &tm)
: targetModel(tm) {
// The first column in the NPU lacks a shim tile. AIE-RT exposes some of
// the internals about how this is modeled in a somewhat awkward way.
size_t partitionStartCol = tm.isVirtualized() ? 1 : 0;
size_t partitionStartCol =
tm.hasProperty(AIETargetModel::IsVirtualized) ? 1 : 0;
size_t partitionNumCols = tm.columns();
size_t deviceRows = tm.rows();
size_t deviceCols = tm.columns() + partitionStartCol;
Expand Down Expand Up @@ -470,7 +471,8 @@ LogicalResult AIERTControl::configureSwitches(DeviceOp &targetOp) {
int32_t col = switchboxOp.colIndex();
int32_t row = switchboxOp.rowIndex();
XAie_LocType tileLoc = XAie_TileLoc(col, row);
assert(targetModel.isNPU() && "Only NPU currently supported");
assert(targetModel.hasProperty(AIETargetModel::IsNPU) &&
"Only NPU currently supported");

Block &b = switchboxOp.getConnections().front();
for (auto connectOp : b.getOps<ConnectOp>())
Expand Down
3 changes: 2 additions & 1 deletion lib/Targets/AIETargetCDODirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ translateToCDODirect(ModuleOp m, llvm::StringRef workDirPath,

// things like XAIE_MEM_TILE_ROW_START and the missing
// shim dma on tile (0,0) are hard-coded assumptions about NPU...
assert(targetModel.isNPU() && "Only NPU currently supported");
assert(targetModel.hasProperty(AIETargetModel::IsNPU) &&
"Only NPU currently supported");

AIERTControl ctl(targetModel);
if (failed(ctl.setIOBackend(aieSim, xaieDebug)))
Expand Down
2 changes: 1 addition & 1 deletion lib/Targets/AIETargetXAIEV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mlir::LogicalResult generateDMAConfig(OpType memOp, raw_ostream &output,
}

if (0 != ndims)
if (isa<AIE1TargetModel>(targetModel))
if (!targetModel.hasProperty(AIETargetModel::UsesMultiDimensionalBDs))
return memOp.emitOpError("DMA contains at least one multi-dimensional "
"buffer descriptor. This is currently only "
"supported for AIE-ML and later devices.");
Expand Down
18 changes: 12 additions & 6 deletions test/CppTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ set(CMAKE_CXX_STANDARD 17)

include(CTest)

add_executable(target_model target_model.cpp)
add_executable(target_model_rtti target_model_rtti.cpp)
add_test(NAME TargetModel COMMAND target_model)
add_test(NAME TargetModelRtti COMMAND target_model_rtti)

add_custom_target(check-aie-cpp COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS target_model_rtti)

get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)

target_link_libraries(target_model_rtti
PUBLIC
AIE
${dialect_libs})
set(EXECUTABLES target_model target_model_rtti)

add_custom_target(check-aie-cpp COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${EXECUTABLES})

foreach(executable ${EXECUTABLES})
target_link_libraries(${executable}
PUBLIC
AIE
${dialect_libs})
endforeach()

add_dependencies(check-aie check-aie-cpp)
Loading
Loading