MCPcopy Create free account
hub / github.com/alibaba/euler / ComputeAsync

Method ComputeAsync

tf_euler/kernels/get_binary_feature_op.cc:60–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58};
59
60void GetBinaryFeature::ComputeAsync(OpKernelContext* ctx, DoneCallback done) {
61 auto nodes = ctx->input(0);
62 auto& shape = nodes.shape();
63
64 std::vector<Tensor*> outputs(N_, nullptr);
65 TensorShape output_shape;
66 output_shape.AddDim(shape.dim_size(0));
67 for (auto i = 0; i < N_; ++i) {
68 OP_REQUIRES_OK(ctx, ctx->allocate_output(i, output_shape, &outputs[i]));
69 }
70
71 auto nodes_flat = nodes.flat<int64>();
72 size_t nodes_size = nodes_flat.size();
73
74 auto query = new euler::Query(query_str_);
75 auto t_nodes = query->AllocInput("nodes", {nodes_size}, euler::kUInt64);
76 for (size_t i = 0; i < feature_names_.size(); ++i) {
77 auto t_fid = query->AllocInput("__" + feature_names_[i], {1},
78 euler::kString);
79 *(t_fid->Raw<std::string*>()[0]) = "binary_" + feature_names_[i];
80 }
81 std::copy(nodes_flat.data(), nodes_flat.data() + nodes_flat.size(),
82 t_nodes->Raw<int64_t>());
83
84 auto callback = [outputs, done, query, nodes_size, this]() {
85 auto results_map = query->GetResult(res_names_);
86 std::stringstream ss;
87 for (size_t i = 0 ; i < feature_names_.size(); ++i) {
88 ss.str("");
89 ss << "fea:" << i * 2;
90 std::string fea_idx = ss.str();
91
92 ss.str("");
93 ss << "fea:" << i * 2 + 1;
94 std::string fea_val = ss.str();
95
96 if (results_map[fea_idx]->NumElements() != nodes_size * 2) {
97 EULER_LOG(FATAL) << "Binary Feature Result Index Num Error:" <<
98 results_map[fea_idx]->NumElements() << "Expect: " << nodes_size * 2;
99 }
100 for (size_t j = 0; j < nodes_size; ++j) {
101 size_t start = results_map[fea_idx]->Raw<int32_t>()[j * 2];
102 size_t end = results_map[fea_idx]->Raw<int32_t>()[j * 2 + 1];
103 auto data = outputs[i]->flat<tensorflow::string>();
104 std::string f_v(end - start, 0);
105 std::copy(results_map[fea_val]->Raw<char>() + start,
106 results_map[fea_val]->Raw<char>() + end,
107 f_v.begin());
108 data(j) = f_v;
109 }
110 }
111 delete query;
112 done();
113 };
114 euler::QueryProxy::GetInstance()->RunAsyncGremlin(query, callback);
115}
116
117REGISTER_KERNEL_BUILDER(

Callers

nothing calls this directly

Calls 7

AllocInputMethod · 0.80
dataMethod · 0.80
GetResultMethod · 0.80
RunAsyncGremlinMethod · 0.80
sizeMethod · 0.45
NumElementsMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected