[ 
https://issues.apache.org/jira/browse/ARROW-1744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16287531#comment-16287531
 ] 

ASF GitHub Bot commented on ARROW-1744:
---------------------------------------

holdenk commented on a change in pull request #1379: ARROW-1744: [WIP] Add 
plasma tensorflow op
URL: https://github.com/apache/arrow/pull/1379#discussion_r156349604
 
 

 ##########
 File path: cpp/src/plasma/tf/plasma_op.cc
 ##########
 @@ -0,0 +1,70 @@
+#include "tensorflow/core/framework/op.h"
+#include "tensorflow/core/framework/op_kernel.h"
+#include "tensorflow/core/framework/shape_inference.h"
+
+#include "arrow/io/memory.h"
+#include "arrow/ipc/reader.h"
+#include "arrow/tensor.h"
+#include "plasma/client.h"
+
+using namespace tensorflow;
+
+REGISTER_OP("PlasmaData")
+    .Input("object_id: string")
+    .Output("output: float32")
+    .Attr("socket: string");
+
+// TODO(pcm): Make this zero-copy if possible
+
+class PlasmaDataOp : public OpKernel {
+ public:
+  explicit PlasmaDataOp(OpKernelConstruction* context) : OpKernel(context) {
+    std::cout << "called constructor" << std::endl;
+    std::string socket;
+    OP_REQUIRES_OK(context, context->GetAttr("socket", &socket));
+    // Connect to plasma
+    ARROW_CHECK_OK(client_.Connect(socket, "", PLASMA_DEFAULT_RELEASE_DELAY));
+    std::cout << "constructor finished" << std::endl;
+  }
+
+  void Compute(OpKernelContext* context) override {
+    // Grab the input tensor
+    const Tensor& input_tensor = context->input(0);
+    auto input = input_tensor.flat<string>();
+
+    // Get the object
+    plasma::ObjectID object_id = plasma::ObjectID::from_binary(input(0));
+    plasma::ObjectBuffer object_buffer;
+    ARROW_CHECK_OK(client_.Get(&object_id, 1, -1, &object_buffer));
+
+    // Get the tensor
+    std::shared_ptr<arrow::Tensor> result;
+    arrow::io::BufferReader reader(object_buffer.data, 
object_buffer.data_size);
+    int64_t offset;
+    ARROW_CHECK_OK(reader.Tell(&offset));
+    ARROW_CHECK_OK(arrow::ipc::ReadTensor(0, &reader, &result));
+
+    std::cout << "shape is" << result->shape()[0] << " , " << 
result->shape()[1]
+              << std::endl;
+
+    // Create an output tensor
+    TensorShape shape(result->shape());
+    Tensor* output_tensor = NULL;
+    OP_REQUIRES_OK(context, context->allocate_output(0, shape, 
&output_tensor));
+    auto output_flat = output_tensor->flat<float>();
+
+    // Set all but the first element of the output tensor to 0.
 
 Review comment:
   Is this comment perhaps about an older version of the code?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> [Plasma] Provide TensorFlow operator to read tensors from plasma
> ----------------------------------------------------------------
>
>                 Key: ARROW-1744
>                 URL: https://issues.apache.org/jira/browse/ARROW-1744
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: Plasma (C++)
>            Reporter: Philipp Moritz
>            Assignee: Philipp Moritz
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>
> see https://www.tensorflow.org/extend/adding_an_op



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to