You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/01/07 08:46:03 UTC

[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #4459: [RUNTIME] Implement TVMDSOOp(TensorFlow custom op) for TVM runtime

FrozenGene commented on a change in pull request #4459: [RUNTIME] Implement TVMDSOOp(TensorFlow custom op) for TVM runtime
URL: https://github.com/apache/incubator-tvm/pull/4459#discussion_r363642770
 
 

 ##########
 File path: src/contrib/tf_op/tvm_dso_op_kernels.cc
 ##########
 @@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <cstdio>
+#include <cuda_runtime.h>
+#include <dlpack/dlpack.h>
+#include <tvm/runtime/module.h>
+#include <tvm/runtime/device_api.h>
+#include <tvm/runtime/registry.h>
+#include <tvm/runtime/packed_func.h>
+#include "tensorflow/core/framework/op_kernel.h"
+
+#include "index_seq.h"
+
+using namespace tensorflow;
+
+typedef Eigen::ThreadPoolDevice CPUDevice;
+typedef Eigen::GpuDevice GPUDevice;
+typedef gtl::InlinedVector<int64, 4> ShapeContainer;
+
+
+template <typename DEVICE_TYPE>
+class TVMDSOOpTrait;
+
+
+class TensorAsBuf {
+  public:
+    Tensor inline_tensor;
+    Tensor* tensor;
+
+    size_t size;
+    size_t offset;
+
+    int device_type;
+
+    char* origin_buf; 
+    char* buf;
+
+    void CopyToOrigin() {
+        if (buf == origin_buf) {
+            return;
+        }
+        if (device_type == kDLCPU) {
+            memcpy(origin_buf, buf + offset, size); 
+        } else {
 
 Review comment:
   It is not a good idea. For example, when we set the context be OpenCL, what happened? we will go into `else`. It is no problem only support CPU and CUDA devices now, but you could implement like this:
   ```
   if (device_type == kDLCPU) {
   
   } else if (device_type == kDLGPU) {
   
   } else {
      LOG(FATAL) << "Only support CPU and CUDA now. Not implemented " << device_type << "currently"; 
   }

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


With regards,
Apache Git Services