wkcn commented on a change in pull request #17510: MXNet FFI for Operator 
Imperative Invocation
URL: https://github.com/apache/incubator-mxnet/pull/17510#discussion_r380126125
 
 

 ##########
 File path: include/mxnet/runtime/packed_func.h
 ##########
 @@ -0,0 +1,1254 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file runtime/packed_func.h
+ * \brief Adapted from incubator-tvm/include/tvm/runtime/packed_func.h
+ * Type-erased function used across MXNET API.
+ */
+#ifndef MXNET_RUNTIME_PACKED_FUNC_H_
+#define MXNET_RUNTIME_PACKED_FUNC_H_
+
+#include <dmlc/logging.h>
+#include <mxnet/runtime/c_runtime_api.h>
+#include <mxnet/runtime/object.h>
+#include <mxnet/runtime/ndarray.h>
+#include <mxnet/runtime/container.h>
+#include <mxnet/runtime/ffi_helper.h>
+#include <mxnet/runtime/data_type.h>
+#include <mxnet/node/container.h>
+#include <mxnet/ir/expr.h>
+#include <mxnet/ndarray.h>
+#include <mxnet/base.h>
+#include <functional>
+#include <tuple>
+#include <vector>
+#include <string>
+#include <limits>
+#include <memory>
+#include <utility>
+#include <type_traits>
+#include <sstream>
+
+namespace mxnet {
+// forward declarations
+// class Integer;
+// class Expr;
+
+namespace runtime {
+
+/*!
+ * \brief Runtime utility for getting custom type name from code
+ * \param type_code Custom type code
+ * \return Custom type name
+ */
+// MXNET_DLL std::string GetCustomTypeName(uint8_t type_code);
+
+/*!
+ * \brief Runtime utility for checking whether custom type is registered
+ * \param type_code Custom type code
+ * \return Bool representing whether type is registered
+ */
+// MXNET_DLL bool GetCustomTypeRegistered(uint8_t type_code);
+
+/*!
+ * \brief Runtime utility for parsing string of the form "custom[<typename>]"
+ * \param s String to parse
+ * \param scan pointer to parsing pointer, which is scanning across s
+ * \return type code of custom type parsed
+ */
+// MXNET_DLL uint8_t ParseCustomDatatype(const std::string& s, const char** 
scan);
+
+/*!
+ * \brief convert a string to TVM type.
+ * \param s The string to be converted.
+ * \return The corresponding tvm type.
+ */
+inline DLDataType String2DLDataType(std::string s);
+
+// forward declarations
+class MXNetArgs;
+class MXNetArgValue;
+class MXNetRetValue;
+class MXNetArgsSetter;
+
+/*!
+ * \brief Packed function is a type-erased function.
+ *  The arguments are passed by packed format.
+ *
+ *  This is an useful unified interface to call generated functions,
+ *  It is the unified function function type of TVM.
+ *  It corresponds to TVMFunctionHandle in C runtime API.
+ */
+class PackedFunc {
+ public:
+  /*!
+   * \brief The internal std::function
+   * \param args The arguments to the function.
+   * \param rv The return value.
+   *
+   * \code
+   *   // Example code on how to implemented FType
+   *   void MyPackedFunc(MXNetArgs args, MXNetRetValue* rv) {
+   *     // automatically convert arguments to desired type.
+   *     int a0 = args[0];
+   *     float a1 = args[1];
+   *     ...
+   *     // automatically assign values to rv
+   *     std::string my_return_value = "x";
+   *     *rv = my_return_value;
+   *   }
+   * \endcode
+   */
+  using FType = std::function<void (MXNetArgs args, MXNetRetValue* rv)>;
 
 Review comment:
   @hzfan I see. Thank you for the detailed explaination : )

----------------------------------------------------------------
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