MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / UpdateCacheValue

Method UpdateCacheValue

oneflow/core/framework/op_kernel_infer_cache.cpp:59–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59void 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
79void OpKernelInferCache::Reset() {
80 CHECK_EQ(cached_key2value_.size(), key_storage_.size());

Callers 1

ForwardShapeMethod · 0.80

Calls 6

ResetFunction · 0.85
ValueTypeEnum · 0.85
sizeMethod · 0.45
resizeMethod · 0.45
outputsMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected