Skip to content

Commit f85a4a9

Browse files
authored
Add hasProperty method to targetModel (#1929)
1 parent 176e7ab commit f85a4a9

File tree

9 files changed

+252
-31
lines changed

9 files changed

+252
-31
lines changed

include/aie/Dialect/AIE/IR/AIETargetModel.h

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ class AIETargetModel {
7171
TK_AIE2_Last = TK_AIE2_NPU2_Last,
7272
};
7373

74+
// One-hot encoded list of target model properties.
75+
enum ModelProperty {
76+
// Device uses semaphore locks.
77+
UsesSemaphoreLocks = 1U << 0,
78+
// Device is an NPU-based device.
79+
// There are several special cases for handling the NPU at the moment.
80+
IsNPU = 1U << 1,
81+
// Device model is virtualized.
82+
// This is used during CDO code generation to configure aie-rt properly.
83+
IsVirtualized = 1U << 2,
84+
// Device uses multi-dimensional buffer descriptors.
85+
UsesMultiDimensionalBDs = 1U << 3,
86+
};
87+
7488
private:
7589
const TargetModelKind kind;
7690

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

235-
// Return true if this is an NPU-based device
236-
// There are several special cases for handling the NPU at the moment.
237-
virtual bool isNPU() const { return false; }
249+
// Return true if this device has a given property.
250+
uint32_t ModelProperties = 0;
251+
bool hasProperty(ModelProperty Prop) const {
252+
return (ModelProperties & Prop) == Prop;
253+
}
238254

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

319335
class AIE2TargetModel : public AIETargetModel {
320336
public:
321-
AIE2TargetModel(TargetModelKind k) : AIETargetModel(k) {}
337+
AIE2TargetModel(TargetModelKind k) : AIETargetModel(k) {
338+
// Device properties initialization
339+
ModelProperties |= AIETargetModel::UsesSemaphoreLocks;
340+
ModelProperties |= AIETargetModel::UsesMultiDimensionalBDs;
341+
}
322342

323343
AIEArch getTargetArch() const override;
324344

@@ -502,7 +522,10 @@ class VE2802TargetModel : public AIE2TargetModel {
502522

503523
class BaseNPUTargetModel : public AIE2TargetModel {
504524
public:
505-
BaseNPUTargetModel(TargetModelKind k) : AIE2TargetModel(k) {}
525+
BaseNPUTargetModel(TargetModelKind k) : AIE2TargetModel(k) {
526+
// Device properties initialization
527+
ModelProperties |= AIETargetModel::IsNPU;
528+
}
506529

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

522545
uint32_t getNumMemTileRows() const override { return 1; }
523546

524-
// Return true if the device model is virtualized. This is used
525-
// during CDO code generation to configure aie-rt properly.
526-
virtual bool isVirtualized() const = 0;
527-
528-
virtual bool isNPU() const override { return true; }
529-
530547
static bool classof(const AIETargetModel *model) {
531548
return model->getKind() >= TK_AIE2_NPU1 &&
532549
model->getKind() < TK_AIE2_NPU2_Last;
@@ -549,8 +566,6 @@ class NPUTargetModel : public BaseNPUTargetModel {
549566
return row == 0 && col == 0;
550567
}
551568

552-
bool isVirtualized() const override { return false; }
553-
554569
static bool classof(const AIETargetModel *model) {
555570
return model->getKind() == TK_AIE2_NPU1;
556571
}
@@ -565,16 +580,17 @@ class VirtualizedNPUTargetModel : public BaseNPUTargetModel {
565580
: BaseNPUTargetModel(static_cast<TargetModelKind>(
566581
static_cast<std::underlying_type_t<TargetModelKind>>(TK_AIE2_NPU1) +
567582
_cols)),
568-
cols(_cols) {}
583+
cols(_cols) {
584+
// Device properties initialization
585+
ModelProperties |= AIETargetModel::IsVirtualized;
586+
}
569587

570588
uint32_t getAddressGenGranularity() const override { return 32; }
571589

572590
int columns() const override { return cols; }
573591

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

576-
bool isVirtualized() const override { return true; }
577-
578594
static bool classof(const AIETargetModel *model) {
579595
return model->getKind() >= TK_AIE2_NPU1_1Col &&
580596
model->getKind() < TK_AIE2_NPU1_Last;
@@ -594,8 +610,6 @@ class NPU2TargetModel : public BaseNPUTargetModel {
594610

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

597-
bool isVirtualized() const override { return false; }
598-
599613
static bool classof(const AIETargetModel *model) {
600614
return model->getKind() == TK_AIE2_NPU2;
601615
}

lib/CAPI/TargetModel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ uint32_t aieTargetModelGetNumBanks(AieTargetModel targetModel, int col,
155155
}
156156

157157
bool aieTargetModelIsNPU(AieTargetModel targetModel) {
158-
return unwrap(targetModel).isNPU();
158+
return unwrap(targetModel).hasProperty(xilinx::AIE::AIETargetModel::IsNPU);
159159
}
160160

161161
uint32_t aieTargetModelGetColumnShift(AieTargetModel targetModel) {

lib/Conversion/AIEToConfiguration/AIEToConfiguration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static LogicalResult convertAIEToConfiguration(AIE::DeviceOp device,
449449
const BaseNPUTargetModel &targetModel =
450450
(const BaseNPUTargetModel &)device.getTargetModel();
451451

452-
if (!targetModel.isNPU())
452+
if (!targetModel.hasProperty(AIETargetModel::IsNPU))
453453
return failure();
454454

455455
bool aieSim = false;

lib/Dialect/AIE/Transforms/AIEObjectFifoStatefulTransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ struct AIEObjectFifoStatefulTransformPass
12221222
target = objFifoLinks[*linkOp];
12231223

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

12271227
if (locksPerFifo[target].size() == 0) {
12281228
for (int i = 0; i < numLocks; i++) {

lib/Targets/AIERT.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ AIERTControl::AIERTControl(const AIE::BaseNPUTargetModel &tm)
5757
: targetModel(tm) {
5858
// The first column in the NPU lacks a shim tile. AIE-RT exposes some of
5959
// the internals about how this is modeled in a somewhat awkward way.
60-
size_t partitionStartCol = tm.isVirtualized() ? 1 : 0;
60+
size_t partitionStartCol =
61+
tm.hasProperty(AIETargetModel::IsVirtualized) ? 1 : 0;
6162
size_t partitionNumCols = tm.columns();
6263
size_t deviceRows = tm.rows();
6364
size_t deviceCols = tm.columns() + partitionStartCol;
@@ -470,7 +471,8 @@ LogicalResult AIERTControl::configureSwitches(DeviceOp &targetOp) {
470471
int32_t col = switchboxOp.colIndex();
471472
int32_t row = switchboxOp.rowIndex();
472473
XAie_LocType tileLoc = XAie_TileLoc(col, row);
473-
assert(targetModel.isNPU() && "Only NPU currently supported");
474+
assert(targetModel.hasProperty(AIETargetModel::IsNPU) &&
475+
"Only NPU currently supported");
474476

475477
Block &b = switchboxOp.getConnections().front();
476478
for (auto connectOp : b.getOps<ConnectOp>())

lib/Targets/AIETargetCDODirect.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ translateToCDODirect(ModuleOp m, llvm::StringRef workDirPath,
142142

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

147148
AIERTControl ctl(targetModel);
148149
if (failed(ctl.setIOBackend(aieSim, xaieDebug)))

lib/Targets/AIETargetXAIEV2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ mlir::LogicalResult generateDMAConfig(OpType memOp, raw_ostream &output,
125125
}
126126

127127
if (0 != ndims)
128-
if (isa<AIE1TargetModel>(targetModel))
128+
if (!targetModel.hasProperty(AIETargetModel::UsesMultiDimensionalBDs))
129129
return memOp.emitOpError("DMA contains at least one multi-dimensional "
130130
"buffer descriptor. This is currently only "
131131
"supported for AIE-ML and later devices.");

test/CppTests/CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ set(CMAKE_CXX_STANDARD 17)
66

77
include(CTest)
88

9+
add_executable(target_model target_model.cpp)
910
add_executable(target_model_rtti target_model_rtti.cpp)
11+
add_test(NAME TargetModel COMMAND target_model)
1012
add_test(NAME TargetModelRtti COMMAND target_model_rtti)
1113

12-
add_custom_target(check-aie-cpp COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS target_model_rtti)
13-
1414
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
1515

16-
target_link_libraries(target_model_rtti
17-
PUBLIC
18-
AIE
19-
${dialect_libs})
16+
set(EXECUTABLES target_model target_model_rtti)
17+
18+
add_custom_target(check-aie-cpp COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${EXECUTABLES})
19+
20+
foreach(executable ${EXECUTABLES})
21+
target_link_libraries(${executable}
22+
PUBLIC
23+
AIE
24+
${dialect_libs})
25+
endforeach()
2026

2127
add_dependencies(check-aie check-aie-cpp)

0 commit comments

Comments
 (0)