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

Conversation

erwei-xilinx
Copy link
Collaborator

@erwei-xilinx erwei-xilinx commented Nov 17, 2024

The hasProperty method checks whether a target model has a given device property (implemented as enum).
List of initial properties added:

  • UsesSemaphoreLocks
  • IsNPU
  • IsVirtualized
  • UsesMultiDimensionalBDs

Copy link
Collaborator

@fifield fifield left a comment

Choose a reason for hiding this comment

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

This is probably better than the current convention which is to test for !aie1. Should we update such cases in this PR or gradually?

include/aie/Dialect/AIE/IR/AIETargetModel.h Outdated Show resolved Hide resolved
@jgmelber
Copy link
Collaborator

Isn't it enough to check if the code is targeting AIE1. Otherwise it has semaphore locks?

@erwei-xilinx
Copy link
Collaborator Author

Isn't it enough to check if the code is targeting AIE1. Otherwise it has semaphore locks?

Functionality wise, yes we can definitely check for aie1. It's just that when other projects such as air use mlir-aie's target models, it isn't so intuitive for outside developers as there isn't a logical connection between "the device is not aie1" and "the device is using semaphore locks".

@erwei-xilinx erwei-xilinx changed the title Add isUsingSemaphoreLocks method to targetModel Add hasProperty method to targetModel Nov 21, 2024
@erwei-xilinx
Copy link
Collaborator Author

This is probably better than the current convention which is to test for !aie1. Should we update such cases in this PR or gradually?

Sure, I updated some cases with the hasProperty method in this PR.

Comment on lines 655 to 661
bool AIE2TargetModel::hasProperty(ModelProperty prop) const {
uint64_t properties = 0;
properties |= AIETargetModel::UsesSemaphoreLocks;
properties |= AIETargetModel::UsesMultiDimensionalBDs;
properties |= AIETargetModel::IsNPU;
return (properties & prop) == prop;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

AIE2 does not imply IsNPU. It should get inherited from BaseNPUTargetModel or BaseNPU3TargetModel.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for finding the bug. Fixed.

// 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.
virtual bool hasProperty(ModelProperty Prop) const = 0;
Copy link
Collaborator

@fifield fifield Nov 21, 2024

Choose a reason for hiding this comment

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

Suggested change
virtual bool hasProperty(ModelProperty Prop) const = 0;
bool hasProperty(ModelProperty Prop) const { return false; }

But it might also be worth looking at how rtti works in AIETargetModel. Using a similar scheme, each subclass would add its bitvector of properties via the call to the base class constructor. The base class would OR the bitvector with its own, so the subclass only needs to add new properties not present in the base class.

#include <iostream>
#include <cstdlib>

class ClassA {
private:
  const uint32_t features;
public:
  ClassA(uint32_t f) : features(f) {}
  uint32_t getFeatures() const { return features; };
};

class ClassB : public ClassA {
  static constexpr uint32_t class_b_features = 0x1;
public:
  ClassB(uint32_t f) : ClassA(f | class_b_features) {}
  ClassB() : ClassA(class_b_features) {}
};

class ClassC : public ClassB {
  static constexpr uint32_t class_c_features = 0x2;
public:
  ClassC() : ClassB(class_c_features) {}
};

class ClassD : public ClassB {
  static constexpr uint32_t class_d_features = 0x4;
public:
  ClassD() : ClassB(class_d_features ) {}
};

int main(int argc, char *argv[]) {
  std::cout << "B " << ClassB().getFeatures() << "\n";
  std::cout << "C " << ClassC().getFeatures() << "\n";
  std::cout << "D " << ClassD().getFeatures() << "\n";
}
$ ./a.out
B 1
C 3
D 5

A side benefit is that the vector of properties gets built once when the TargetModel objects are created, instead of each time hasProperty() is called.

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. PR updated. Thanks!

Comment on lines 292 to 296
bool AIE1TargetModel::hasProperty(ModelProperty prop) const {
uint64_t properties = 0;
return (properties & prop) == prop;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't add anything and can be covered by the base class AIETargetModel ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. Now removed in PR.

@erwei-xilinx erwei-xilinx added this pull request to the merge queue Nov 22, 2024
Merged via the queue into Xilinx:main with commit f85a4a9 Nov 22, 2024
52 checks passed
@erwei-xilinx erwei-xilinx deleted the isUsingSemaphoreLock_method branch November 22, 2024 01:55
// 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants