MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / FindOrCreate

Method FindOrCreate

tensorflow/core/framework/op_segment.cc:38–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38Status OpSegment::FindOrCreate(const string& session_handle,
39 const string& node_name, OpKernel** kernel,
40 CreateKernelFn create_fn) {
41 {
42 mutex_lock l(mu_);
43 auto item = gtl::FindPtrOrNull(sessions_, session_handle);
44 if (item == nullptr) {
45 return errors::NotFound("Session ", session_handle, " is not found.");
46 }
47 *kernel = gtl::FindPtrOrNull(item->name_kernel, node_name);
48 if (*kernel != nullptr) {
49 return Status::OK();
50 }
51 }
52 Status s = create_fn(kernel);
53 if (!s.ok()) {
54 LOG(ERROR) << "Create kernel failed: " << s;
55 return s;
56 }
57 {
58 mutex_lock l(mu_);
59 auto item = gtl::FindPtrOrNull(sessions_, session_handle);
60 if (item == nullptr) {
61 return errors::NotFound("Session ", session_handle, " is not found.");
62 }
63 OpKernel** p_kernel = &(item->name_kernel[node_name]);
64 if (*p_kernel == nullptr) {
65 *p_kernel = *kernel; // Inserts 'kernel' in the map.
66 } else {
67 delete *kernel;
68 *kernel = *p_kernel;
69 }
70 }
71 return Status::OK();
72}
73
74void OpSegment::AddHold(const string& session_handle) {
75 mutex_lock l(mu_);

Callers 2

RecvBufAsyncMethod · 0.45
TEST_FFunction · 0.45

Calls 3

FindPtrOrNullFunction · 0.85
NotFoundFunction · 0.85
okMethod · 0.45

Tested by 1

TEST_FFunction · 0.36