| 35 | }; |
| 36 | |
| 37 | void SampleGraphLabel::ComputeAsync(OpKernelContext* ctx, DoneCallback done) { |
| 38 | auto batch_size = ctx->input(0); |
| 39 | auto batch_size_flat = batch_size.flat<int32>(); |
| 40 | int32_t batch_size_num = batch_size_flat(0); |
| 41 | |
| 42 | Tensor* output = nullptr; |
| 43 | TensorShape output_shape; |
| 44 | output_shape.AddDim(batch_size_num); |
| 45 | OP_REQUIRES_OK(ctx, ctx->allocate_output(0, output_shape, &output)); |
| 46 | |
| 47 | auto query = new euler::Query( |
| 48 | "API_SAMPLE_GRAPH_LABEL", "sample_graph", 1, |
| 49 | {"count"}, {}); |
| 50 | euler::Tensor* count_t = query->AllocInput( |
| 51 | "count", {1}, euler::DataType::kInt32); |
| 52 | count_t->Raw<int32_t>()[0] = batch_size_num; |
| 53 | |
| 54 | auto callback = [output, done, query, batch_size_num, this]() { |
| 55 | euler::Tensor* graph_labels = query->GetResult("sample_graph:0"); |
| 56 | std::string result_s(graph_labels->Raw<char>(), |
| 57 | graph_labels->NumElements()); |
| 58 | std::vector<std::string> results_vec = euler::Split(result_s, ","); |
| 59 | if (results_vec.size() != batch_size_num) { |
| 60 | EULER_LOG(FATAL) << "results_vec size != batch_size_num"; |
| 61 | } |
| 62 | auto data = output->flat<tensorflow::string>(); |
| 63 | for (size_t i = 0; i < batch_size_num; ++i) { |
| 64 | data(i) = results_vec[i]; |
| 65 | } |
| 66 | delete query; |
| 67 | done(); |
| 68 | }; |
| 69 | euler::QueryProxy::GetInstance()->RunAsyncGremlin(query, callback); |
| 70 | } |
| 71 | |
| 72 | REGISTER_KERNEL_BUILDER( |
| 73 | Name("SampleGraphLabel").Device(DEVICE_CPU), SampleGraphLabel); |
nothing calls this directly
no test coverage detected