The static fetch function can be used to specialize the fetch of a specific object from the cache. It can be used to select the best object among a number of matched cache objects. It can also be used to remove other objects that are not needed in the cache anymore. Here, it fetches the biggest payload OP among cache items and remove all other OPs from the cache. It is ok to remove them since the
| 106 | // It is ok to remove them since the biggest payload OP can be used to accomodate all of them, |
| 107 | // so they will never be reused and thus are no longer necessary. |
| 108 | static std::shared_ptr<nvcvpy::ICacheItem> fetch(std::vector<std::shared_ptr<nvcvpy::ICacheItem>> &cache) |
| 109 | { |
| 110 | assert(!cache.empty()); |
| 111 | |
| 112 | std::shared_ptr<nvcvpy::ICacheItem> retItem = cache[0]; |
| 113 | size_t maxPayloadSize = 0; |
| 114 | |
| 115 | for (const auto &item : cache) |
| 116 | { |
| 117 | const Key &key = static_cast<const Key &>(item.get()->key()); |
| 118 | size_t keyPayloadSize = key.payloadSize(); |
| 119 | |
| 120 | if (keyPayloadSize > maxPayloadSize) |
| 121 | { |
| 122 | maxPayloadSize = keyPayloadSize; |
| 123 | retItem = item; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | cache.clear(); |
| 128 | |
| 129 | nvcvpy::Cache::removeAllNotInUseMatching(retItem.get()->key()); |
| 130 | |
| 131 | return retItem; |
| 132 | } |
| 133 | |
| 134 | private: |
| 135 | Key m_key; |
nothing calls this directly
no test coverage detected