* Some pass creates datas duplicate with a different order from time to time (because of unordered_set usage). It leads to a different order in model->datas() list and affects the shape allocation process which relies on this order.
* Make shape allocation be relied on topological order of datas which is stable and doesn't depend on order datas creation during different passes.
* Allocates memory for single data node
*/
bool allocateData(const Data& data);
- ShapeLocation allocateShape(Data& data);
+ ShapeLocation allocateShape(const Data& data);
void freeData(const Data& data, DeallocationMode mode = DeallocationMode::JustFree);
void selfCheck();
int dimsOffset;
Location stridesLocation;
int stridesOffset;
+
+ bool operator==(const ShapeLocation& shapeLocation) const {
+ return std::tie(dimsLocation, dimsOffset, stridesLocation, stridesOffset) ==
+ std::tie(shapeLocation.dimsLocation, shapeLocation.dimsOffset, shapeLocation.stridesLocation, shapeLocation.stridesOffset);
+ }
+
+ bool operator!=(const ShapeLocation& shapeLocation) const {
+ return !(*this == shapeLocation);
+ }
};
static constexpr ShapeLocation defaultShapeLocation = {
- Location::None, 0, Location::None, 0
+ Location::None, 0, Location::None, 0
};
//
void setShapeAllocationInfo(const ShapeLocation& shapeLocation);
+ bool isShapeAllocated() const;
+
//
// Backend utilities
//
return chunk->memType == memoryType;
}
-ShapeLocation Allocator::allocateShape(Data& data) {
+ShapeLocation Allocator::allocateShape(const Data& data) {
ShapeLocation shapeLocation;
const auto dimsByteSize = data->desc().dimsByteSize();
//
if (enableShapeAllocation == EnableShapeAllocation::YES) {
- for (auto data : model->datas()) {
- const auto shapeLocation = allocator.allocateShape(data);
- data->setShapeAllocationInfo(shapeLocation);
+ for (const auto& stage : model->getStages()) {
+ const auto& allocateShape = [&allocator](const Data& data) {
+ if (!data->isShapeAllocated()) {
+ const auto shapeLocation = allocator.allocateShape(data);
+ data->setShapeAllocationInfo(shapeLocation);
+ }
+ };
+
+ for (const auto& input : stage->inputs()) {
+ allocateShape(input);
+ }
+ for (const auto& output : stage->outputs()) {
+ allocateShape(output);
+ }
+ for (const auto& tempBuffer : stage->tempBuffers()) {
+ allocateShape(tempBuffer);
+ }
}
}
_shapeLocation = shapeLocation;
}
+bool DataNode::isShapeAllocated() const {
+ return _shapeLocation != defaultShapeLocation;
+}
+
void DataNode::serializeBuffer(
BlobSerializer& serializer) {
serializeDescImpl(serializer, _desc, this->shapeLocation());