1 #ifndef _NNDEPLOY_DAG_BASE_H_
2 #define _NNDEPLOY_DAG_BASE_H_
76 #if defined(__clang__)
77 constexpr
auto prefix = std::string_view(
"[T = ");
78 constexpr
auto suffix =
"]";
79 constexpr
auto function = std::string_view(__PRETTY_FUNCTION__);
80 #elif defined(__GNUC__)
81 constexpr
auto prefix = std::string_view(
"with T = ");
82 constexpr
auto suffix =
"]";
83 constexpr
auto function = std::string_view(__PRETTY_FUNCTION__);
84 #elif defined(_MSC_VER)
85 constexpr
auto prefix = std::string_view(
"type_name<");
86 constexpr
auto suffix =
">(void)";
87 constexpr
auto function = std::string_view(__FUNCSIG__);
89 return std::type_index(
typeid(T)).name();
92 const size_t start =
function.find(prefix) + prefix.size();
93 const size_t end =
function.find(suffix, start);
94 std::string_view type_view =
function.substr(start, end - start);
97 std::string type_str(type_view);
98 size_t semicolon_pos = type_str.find(
';');
99 if (semicolon_pos != std::string::npos) {
100 return type_str.substr(0, semicolon_pos);
107 const std::string& type_name_with_namespace);
127 if (
this != &other) {
144 template <
typename T>
146 typedef typename std::decay<T>::type DT;
147 if constexpr (std::is_same<DT, device::Buffer>::value) {
151 #ifdef ENABLE_NNDEPLOY_OPENCV
152 else if constexpr (std::is_same<DT, cv::Mat>::value) {
157 else if constexpr (std::is_same<DT, device::Tensor>::value) {
160 }
else if constexpr (std::is_base_of<base::Param, DT>::value) {
167 type_name_ = std::string(typeName<DT>());
168 type_ptr_ = &
typeid(DT);
169 type_holder_ = std::make_shared<TypeHolder<DT>>();
176 type_name_ = type_name;
183 std::string base_name = type_name_;
189 std::stringstream ss;
190 ss << base_name <<
"_" << timestamp;
194 const std::type_info*
getTypePtr()
const {
return type_ptr_; }
196 template <
typename T>
198 return (type_ptr_ !=
nullptr) && (*type_ptr_ ==
typeid(T));
201 template <
typename T,
typename... Args>
209 return new T(std::forward<Args>(args)...);
212 template <
typename T>
214 if (type_ptr_ ==
nullptr) {
219 if (*type_ptr_ !=
typeid(T)) {
228 void setEdgeName(
const std::string& edge_name) { edge_name_ = edge_name; }
238 template <
typename T>
245 const std::type_info* type_ptr_{
nullptr};
262 bool is_running =
false;
263 size_t graph_run_size = 0;
265 size_t completed_size = 0;
266 float cost_time = -1.0f;
267 float average_time = -1.0f;
268 float init_time = -1.0f;
279 RunStatus(
const std::string& node_name,
bool is_running,
280 size_t graph_run_size,
size_t run_size,
size_t completed_size,
281 float cost_time,
float average_time,
float init_time)
282 : node_name(node_name),
283 is_running(is_running),
284 graph_run_size(graph_run_size),
286 completed_size(completed_size),
287 cost_time(cost_time),
288 average_time(average_time),
289 init_time(init_time) {}
291 : node_name(other.node_name),
292 is_running(other.is_running),
293 graph_run_size(other.graph_run_size),
294 run_size(other.run_size),
295 completed_size(other.completed_size),
296 cost_time(other.cost_time),
297 average_time(other.average_time),
298 init_time(other.init_time) {}
300 if (
this != &other) {
316 }
else if (run_size > 0 && completed_size > 0 &&
317 run_size == completed_size) {
319 }
else if (run_size == 0 && completed_size == 0 &&
320 std::abs(init_time + 1.0f) < 1e-6) {
322 }
else if (run_size == 0 && completed_size == 0 &&
EdgeTypeInfo(const EdgeTypeInfo &other)
std::string getEdgeName() const
T * createType(Args &&... args)
std::string getTypeName() const
EdgeTypeInfo & operator=(const EdgeTypeInfo &other)
void setTypeName(const std::string &type_name)
std::string getTypeNameWithNamespace() const
std::string getUniqueTypeName()
bool operator!=(const EdgeTypeInfo &other) const
const std::type_info * getTypePtr() const
void setEdgeName(const std::string &edge_name)
EdgeTypeFlag getType() const
bool operator==(const EdgeTypeInfo &other) const
std::shared_ptr< TypeHolderBase > type_holder_
const std::type_info * type_ptr_
#define NNDEPLOY_LOGE(fmt,...)
#define NNDEPLOY_CC_API
api
std::string getUniqueString()
std::string removeNamespace(const std::string &type_name_with_namespace)
std::string ioTypeToString(IOType io_type)
NodeType stringToNodeType(const std::string &node_type_str)
IOType stringToIoType(const std::string &io_type_str)
std::string nodeTypeToString(NodeType node_type)
base::Status abs(device::Tensor *input, device::Tensor *output)
virtual ~TypeHolderBase()=default
RunStatus(const std::string &node_name, bool is_running, size_t graph_run_size, size_t run_size, size_t completed_size, float cost_time, float average_time, float init_time)
RunStatus(const RunStatus &other)
RunStatus & operator=(const RunStatus &other)