| 57 | } |
| 58 | |
| 59 | void OpKernelInferCache::UpdateCacheValue(KernelInferContext* ctx) { |
| 60 | // TODO: make max size configurable |
| 61 | if (cached_key2value_.size() >= kReleaseInIndependentThreadThreshold) { Reset(); } |
| 62 | auto* cache_value = new OpInferCacheValue(); |
| 63 | cache_value->obn_idx2shape_sym.resize(ctx->outputs().size()); |
| 64 | FOR_RANGE(int, i, 0, ctx->outputs().size()) { |
| 65 | const auto& out_arg_pair = ctx->outputs().at(i); |
| 66 | const ShapeView& out_shape_view = |
| 67 | ctx->ShapeView4ArgNameAndIndex(out_arg_pair.first, out_arg_pair.second); |
| 68 | Shape out_shape; |
| 69 | out_shape_view.ToShape(&out_shape); |
| 70 | cache_value->obn_idx2shape_sym.at(i).reset(out_shape); |
| 71 | } |
| 72 | KeyType* new_key = new KeyType(cache_key_); |
| 73 | key_storage_.emplace_back(new_key); |
| 74 | size_t hash_value = std::hash<KeyType>()(cache_key_); |
| 75 | HashEqTraitPtr<const KeyType> ptr_wrapper(new_key, hash_value); |
| 76 | CHECK(cached_key2value_.emplace(ptr_wrapper, ValueType(cache_value)).second); |
| 77 | } |
| 78 | |
| 79 | void OpKernelInferCache::Reset() { |
| 80 | CHECK_EQ(cached_key2value_.size(), key_storage_.size()); |
no test coverage detected