CGroupInfo::CGroupInfo(shared_ptr<Graph> g){ m_groupSize.clear(); m_groupMembers.clear(); m_groupMembersSize.clear(); m_groupMembersInpSize.clear(); printf("CG0 \n"); for (auto it = g->begin(); it != g->end(); ++it) { printf("CG1 \n"); Node *n = *it; if(kConcat == n->kind()) { printf("CG2 \n"); string groupname = n->output()->uniqueName(); //Value's uniqueName is unique, so can be used as key printf("groupname = %s\n", groupname); m_groupSize[groupname] = getValueSize(n->output()); for(int i = 0; i < n->inputs().size(); i++) { printf("CG3 \n"); Node *inp = n->inputs()[i]->node(); if(n->inputs()[i]->node()->kind() == kParam) { printf("CG4 \n"); continue; } m_groupMembers[groupname].push_back(n->inputs()[i]->uniqueName()); m_groupMembersSize[groupname].push_back(getValueSize(n->inputs()[i])); m_groupMembersInpSize[inp->inputs()[0]->uniqueName()] = getValueSize(inp->inputs()[0]); } } else if(n->inputs().size() > 0 && isGraphInput(g,n)) { printf("CG5 \n"); m_groupSize["group_input"] += getValueSize(n->inputs()[0]); m_groupMembers["group_input"].push_back(n->inputs()[0]->uniqueName()); m_groupMembersSize["group_input"].push_back(getValueSize(n->inputs()[0])); } else if(kTransLayoutAfterSlice == n->kind()) { printf("CG6 \n"); string groupname = n->output()->uniqueName(); //Value's uniqueName is unique, so can be used as key m_groupSize[groupname] = getValueSize(n->output()); for(int i = 0; i < n->inputs().size(); i++) { printf("CG7 \n"); Node *inp = n->inputs()[i]->node(); m_groupMembers[groupname].push_back(n->inputs()[i]->uniqueName()); m_groupMembersSize[groupname].push_back(getValueSize(n->inputs()[i])); m_groupMembersInpSize[inp->inputs()[0]->uniqueName()] = getValueSize(inp->inputs()[0]); } } } }这段是什么意思
时间: 2024-03-19 12:39:54 浏览: 18
这段代码实现了一个名为CGroupInfo的类的构造函数,该类用于保存给定图中的节点分组信息。构造函数传入一个指向Graph对象的shared_ptr智能指针,然后遍历图中的每个节点,当遇到kConcat节点时,将其输出的唯一名称作为键,其输入节点的唯一名称和大小信息作为值存储在m_groupMembers、m_groupMembersSize、m_groupMembersInpSize等成员变量中,当遇到kTransLayoutAfterSlice节点时也是同样的处理方式,当遇到图的输入节点时,将其唯一名称和大小信息也存储在m_groupMembers、m_groupMembersSize、m_groupMembersInpSize等成员变量中。最终,CGroupInfo对象包含了图中每个节点的分组信息。
相关问题
shared_ptr<char> 跟 shared_ptr<string> 的区别
shared_ptr<char> 和 shared_ptr<string> 的区别在于它们所管理的对象类型不同。
shared_ptr<char> 是一个智能指针,用于管理指向字符类型的动态内存。它可以自动地跟踪和释放所管理的内存,避免内存泄漏和悬空指针的问题。你可以使用 shared_ptr<char> 来动态分配和释放字符数组,例如:
```cpp
shared_ptr<char> ptr(new char[10]);
```
而 shared_ptr<string> 则是用于管理指向字符串类型的动态内存。它与 shared_ptr<char> 不同之处在于,它可以自动地管理字符串对象的生命周期,包括构造、拷贝和销毁。你可以使用 shared_ptr<string> 来动态分配和释放字符串对象,例如:
```cpp
shared_ptr<string> ptr(new string("Hello"));
```
总结一下:
- shared_ptr<char> 用于管理字符类型的动态内存。
- shared_ptr<string> 用于管理字符串类型的动态内存。
std::atomic<std::shared_ptr<T>>
std::atomic is a C++ class template that provides atomic operations on its template parameter. In this case, the template parameter is std::shared_ptr<T>, which is a type of smart pointer that manages a reference-counted object.
The std::atomic<std::shared_ptr<T>> class template ensures that operations on the shared_ptr object are atomic, meaning that they are indivisible and cannot be interrupted by other threads. This prevents race conditions and ensures that the shared_ptr object is always in a consistent state.
The atomic operations provided by std::atomic<std::shared_ptr<T>> include load, store, and exchange. These operations allow multiple threads to access and modify the shared_ptr object without causing data races or other synchronization issues.
Overall, std::atomic<std::shared_ptr<T>> is a powerful tool for managing shared resources in a multithreaded environment, providing a safe and efficient way to share data between threads.