2022-07-31 21:43:26 +08:00
|
|
|
#pragma once
|
|
|
|
#include "core/common.h"
|
2022-08-05 12:50:34 +08:00
|
|
|
#include "ref.h"
|
2022-07-31 21:43:26 +08:00
|
|
|
|
2022-08-07 21:12:17 +08:00
|
|
|
namespace infini {
|
2022-07-31 21:43:26 +08:00
|
|
|
|
2023-02-12 18:27:52 +08:00
|
|
|
using UidBaseType = int;
|
2022-07-31 21:43:26 +08:00
|
|
|
|
2023-02-12 18:27:52 +08:00
|
|
|
class Uid {
|
2022-07-31 21:43:26 +08:00
|
|
|
private:
|
2023-02-12 18:27:52 +08:00
|
|
|
UidBaseType uid;
|
2022-07-31 21:43:26 +08:00
|
|
|
|
2023-02-12 18:27:52 +08:00
|
|
|
public:
|
|
|
|
Uid(UidBaseType uid) : uid(uid) {}
|
|
|
|
Uid &operator=(const Uid &rhs) = delete;
|
|
|
|
|
|
|
|
operator UidBaseType() const { return uid; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class Guid : public Uid {
|
2022-07-31 21:43:26 +08:00
|
|
|
private:
|
2023-02-12 18:27:52 +08:00
|
|
|
UidBaseType generateGuid() {
|
|
|
|
static UidBaseType guidCnt = 0;
|
2022-07-31 21:43:26 +08:00
|
|
|
return ++guidCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2023-02-12 18:27:52 +08:00
|
|
|
Guid() : Uid(generateGuid()) {}
|
|
|
|
Guid(const Guid &rhs) : Uid(generateGuid()) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Family unique ID. Cloned tensors shared the same FUID.
|
|
|
|
*/
|
|
|
|
class Fuid : public Uid {
|
|
|
|
private:
|
|
|
|
UidBaseType generateFuid() {
|
|
|
|
static UidBaseType fuidCnt = 0;
|
|
|
|
return ++fuidCnt;
|
2022-07-31 21:43:26 +08:00
|
|
|
}
|
|
|
|
|
2023-02-12 18:27:52 +08:00
|
|
|
public:
|
|
|
|
Fuid() : Uid(generateFuid()) {}
|
|
|
|
Fuid(const Fuid &fuid) : Uid(fuid) {}
|
2022-07-31 21:43:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class Object {
|
|
|
|
protected:
|
|
|
|
Guid guid;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~Object(){};
|
|
|
|
virtual string toString() const = 0;
|
|
|
|
void print() { std::cout << toString() << std::endl; }
|
2023-02-12 18:27:52 +08:00
|
|
|
UidBaseType getGuid() const { return guid; }
|
2022-07-31 21:43:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
inline std::ostream &operator<<(std::ostream &os, const Object &obj) {
|
|
|
|
os << obj.toString();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2022-08-05 12:50:34 +08:00
|
|
|
// Overload for Ref-wrapped Object
|
|
|
|
template <typename T,
|
|
|
|
typename std::enable_if_t<std::is_base_of_v<Object, T>> * = nullptr>
|
|
|
|
inline std::ostream &operator<<(std::ostream &os, const Ref<T> &obj) {
|
|
|
|
os << obj->toString();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2023-04-18 15:10:33 +08:00
|
|
|
} // namespace infini
|