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

Don't store AIEDevice enum in TargetModel #1532

Merged
merged 2 commits into from
Jun 4, 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
2 changes: 1 addition & 1 deletion include/aie-c/TargetModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
}; \
typedef struct name name

DEFINE_C_API_STRUCT(AieTargetModel, uint32_t);
DEFINE_C_API_STRUCT(AieTargetModel, uint64_t);

#undef DEFINE_C_API_STRUCT

Expand Down
25 changes: 9 additions & 16 deletions include/aie/Dialect/AIE/IR/AIETargetModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ using TileID = struct TileID {

class AIETargetModel {
public:
AIETargetModel(AIEDevice device) : device(device) {}
AIETargetModel() = default;

virtual ~AIETargetModel();

Expand Down Expand Up @@ -204,17 +204,11 @@ class AIETargetModel {
// 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 the AIEDevice for this target model
AIEDevice getDevice() const { return device; }

private:
AIEDevice device;
};

class AIE1TargetModel : public AIETargetModel {
public:
AIE1TargetModel(AIEDevice device) : AIETargetModel(device) {}
AIE1TargetModel() = default;

bool isCoreTile(int col, int row) const override { return row > 0; }
bool isMemTile(int col, int row) const override { return false; }
Expand Down Expand Up @@ -278,7 +272,7 @@ class AIE1TargetModel : public AIETargetModel {

class AIE2TargetModel : public AIETargetModel {
public:
AIE2TargetModel(AIEDevice device) : AIETargetModel(device) {}
AIE2TargetModel() = default;

AIEArch getTargetArch() const override;

Expand Down Expand Up @@ -335,7 +329,7 @@ class VC1902TargetModel : public AIE1TargetModel {
2, 3, 6, 7, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 46, 47};

public:
VC1902TargetModel(AIEDevice device) : AIE1TargetModel(device) {}
VC1902TargetModel() = default;

int columns() const override { return 50; }

Expand All @@ -358,7 +352,7 @@ class VE2302TargetModel : public AIE2TargetModel {
llvm::SmallDenseSet<unsigned, 8> nocColumns = {2, 3, 6, 7, 10, 11};

public:
VE2302TargetModel(AIEDevice device) : AIE2TargetModel(device) {}
VE2302TargetModel() = default;

int columns() const override { return 17; }

Expand Down Expand Up @@ -410,7 +404,7 @@ class VE2802TargetModel : public AIE2TargetModel {
22, 23, 30, 31, 34, 35};

public:
VE2802TargetModel(AIEDevice device) : AIE2TargetModel(device) {}
VE2802TargetModel() = default;

int columns() const override { return 38; }

Expand Down Expand Up @@ -462,7 +456,7 @@ class VE2802TargetModel : public AIE2TargetModel {

class BaseNPUTargetModel : public AIE2TargetModel {
public:
BaseNPUTargetModel(AIEDevice device) : AIE2TargetModel(device) {}
BaseNPUTargetModel() = default;

int rows() const override {
return 6; /* 1 Shim row, 1 memtile row, and 4 Core rows. */
Expand Down Expand Up @@ -494,7 +488,7 @@ class BaseNPUTargetModel : public AIE2TargetModel {
// The full Phoenix NPU
class NPUTargetModel : public BaseNPUTargetModel {
public:
NPUTargetModel(AIEDevice device) : BaseNPUTargetModel(device) {}
NPUTargetModel() = default;

int columns() const override { return 5; }

Expand All @@ -515,8 +509,7 @@ class VirtualizedNPUTargetModel : public BaseNPUTargetModel {
int cols;

public:
VirtualizedNPUTargetModel(AIEDevice device, int _cols)
: BaseNPUTargetModel(device), cols(_cols) {}
VirtualizedNPUTargetModel(int _cols) : cols(_cols) {}

int columns() const override { return cols; }

Expand Down
4 changes: 2 additions & 2 deletions lib/CAPI/TargetModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
using namespace mlir;

static inline AieTargetModel wrap(const xilinx::AIE::AIETargetModel &tm) {
return AieTargetModel{static_cast<uint32_t>(tm.getDevice())};
return AieTargetModel{reinterpret_cast<std::uintptr_t>(&tm)};
}

static inline const xilinx::AIE::AIETargetModel &unwrap(AieTargetModel tm) {
return xilinx::AIE::getTargetModel(static_cast<xilinx::AIE::AIEDevice>(tm.d));
return *reinterpret_cast<const xilinx::AIE::AIETargetModel *>(tm.d);
}

AieTargetModel aieGetTargetModel(uint32_t device) {
Expand Down
16 changes: 8 additions & 8 deletions lib/Dialect/AIE/IR/AIEDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ LogicalResult myVerifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op) {
return success();
}

static VC1902TargetModel VC1902model(AIEDevice::xcvc1902);
static VE2302TargetModel VE2302model(AIEDevice::xcve2302);
static VE2802TargetModel VE2802model(AIEDevice::xcve2802);
static NPUTargetModel NPUmodel(AIEDevice::npu1);
static VirtualizedNPUTargetModel NPUmodel1col(AIEDevice::npu1_1col, 1);
static VirtualizedNPUTargetModel NPUmodel2col(AIEDevice::npu1_2col, 2);
static VirtualizedNPUTargetModel NPUmodel3col(AIEDevice::npu1_3col, 3);
static VirtualizedNPUTargetModel NPUmodel4col(AIEDevice::npu1_4col, 4);
static VC1902TargetModel VC1902model;
static VE2302TargetModel VE2302model;
static VE2802TargetModel VE2802model;
static NPUTargetModel NPUmodel;
static VirtualizedNPUTargetModel NPUmodel1col(1);
static VirtualizedNPUTargetModel NPUmodel2col(2);
static VirtualizedNPUTargetModel NPUmodel3col(3);
static VirtualizedNPUTargetModel NPUmodel4col(4);

const AIETargetModel &getTargetModel(Operation *op) {
if (auto t = dyn_cast<AIETarget>(op))
Expand Down
Loading