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

Method ComputeAsync

tf_euler/kernels/sample_edge_op.cc:35–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33};
34
35void SampleEdge::ComputeAsync(OpKernelContext* ctx, DoneCallback done) {
36 auto count = ctx->input(0);
37 auto edge_type = ctx->input(1);
38 OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(count.shape()),
39 errors::InvalidArgument("count must be a scalar, saw shape: ",
40 count.shape().DebugString()));
41 OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(edge_type.shape()),
42 errors::InvalidArgument("edge_type must be a scalar, saw shape: ",
43 edge_type.shape().DebugString()));
44 auto count_value = (count.scalar<int32>())();
45 auto type_value = (edge_type.scalar<int32>())();
46
47 TensorShape output_shape;
48 output_shape.AddDim(count_value);
49 output_shape.AddDim(3);
50
51 Tensor* output = nullptr;
52 OP_REQUIRES_OK(ctx, ctx->allocate_output(0, output_shape, &output));
53
54 // build euler gremlin query
55 auto query = new euler::Query("sampleE(edge_type, count).as(eid)");
56 auto t_edge_type = query->AllocInput("edge_type", {1}, euler::kInt32);
57 auto t_count = query->AllocInput("count", {1}, euler::kInt32);
58 *(t_edge_type->Raw<int32_t>()) = type_value;
59 *(t_count->Raw<int32_t>()) = count_value;
60
61 auto callback = [output, done, query] () {
62 auto res = query->GetResult("eid:0");
63 auto res_data = res->Raw<uint64_t>();
64 auto data = output->flat<int64>().data();
65 std::copy(res_data, res_data + res->NumElements(), data);
66 delete query;
67 done();
68 };
69 euler::QueryProxy::GetInstance()->RunAsyncGremlin(query, callback);
70}
71
72REGISTER_KERNEL_BUILDER(Name("SampleEdge").Device(DEVICE_CPU), SampleEdge);
73

Callers

nothing calls this directly

Calls 6

AllocInputMethod · 0.80
GetResultMethod · 0.80
dataMethod · 0.80
RunAsyncGremlinMethod · 0.80
DebugStringMethod · 0.45
NumElementsMethod · 0.45

Tested by

no test coverage detected