rondogency commented on a change in pull request #15921: dynamic custom 
operator support
URL: https://github.com/apache/incubator-mxnet/pull/15921#discussion_r335767549
 
 

 ##########
 File path: example/extensions/lib_custom_op/gemm_lib.cc
 ##########
 @@ -0,0 +1,233 @@
+/*
+ * 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.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file gemm_lib.cc
+ * \brief Sample 2D gemm custom operator implementation library file
+ */
+
+#include <iostream>
+#include "lib_api.h"
+
+// main matrix multiplication routine
+void gemm(const float* A, const float* B, float* C,
+          const unsigned n, const unsigned k, const unsigned m) {
+  unsigned i, j, kk;
+  for (i = 0; i < n; i++) {
+    for (j = 0; j < m; j++) {
+      C[i*m+j] = 0;
+      for (kk = 0; kk < k; kk++) {
+        C[i*m+j] += A[i*k+kk] * B[kk*m+j];
+      }
+    }
+  }
+}
+
+void transpose(const float* A, float* At, const unsigned n, const unsigned m) {
+  unsigned i, j;
+  for (i = 0; i < n; i++) {
+    for (j = 0; j < m; j++) {
+      At[i*m+j] = A[j*n+i];
+    }
+  }
+}
+
+/*
+ * Executes C = A * B
+ * inputs[0] = A; inputs[1] = B; outputs[0] = C
+ */
+MXReturnValue forward(std::map<std::string, std::string> attrs,
+                      std::vector<MXTensor> inputs,
+                      std::vector<MXTensor> outputs,
+                      OpResource res) {
+  // simple example of using runtime data type
+  if (inputs[0].dtype == kFloat32) {
 
 Review comment:
   @eric-haibin-lin in the current implementation, we make user hard-code the 
data type they wanna cast to, which mitigates the burden of using the lengthy 
MSHADOW_TYPE_SWITCH macro. I am just wondering as a user if you would prefer 
this or the implementation mxnet is current using?
   
   This question also applies for the upcoming gpu support: does users wanna 
use Kernel interface, or they wanna write the cuda launch code themselves?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to