-
Notifications
You must be signed in to change notification settings - Fork 96
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
Add hasProperty
method to targetModel
#1929
Conversation
…ces which use semaphore locks
There was a problem hiding this 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?
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". |
isUsingSemaphoreLocks
method to targetModelhasProperty
method to targetModel
Sure, I updated some cases with the |
…emaphoreLock_method
bool AIE2TargetModel::hasProperty(ModelProperty prop) const { | ||
uint64_t properties = 0; | ||
properties |= AIETargetModel::UsesSemaphoreLocks; | ||
properties |= AIETargetModel::UsesMultiDimensionalBDs; | ||
properties |= AIETargetModel::IsNPU; | ||
return (properties & prop) == prop; | ||
} |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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!
bool AIE1TargetModel::hasProperty(ModelProperty prop) const { | ||
uint64_t properties = 0; | ||
return (properties & prop) == prop; | ||
} | ||
|
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
// 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be private
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR created: #1944
The
hasProperty
method checks whether a target model has a given device property (implemented asenum
).List of initial properties added: