aaronmarkham commented on a change in pull request #17486: Update CustomOp doc
with changes for GPU support
URL: https://github.com/apache/incubator-mxnet/pull/17486#discussion_r373217041
##########
File path: example/extensions/lib_custom_op/README.md
##########
@@ -146,21 +168,154 @@ Let’s take a closer look at those registry functions:
* **inferShape**: This function is similar to the `inferType` function, except
it is used for populating the output data shapes. You need to figure out the
shapes of each output tensors for this computation. For example, if the inputs
are images with shape (224,224,3) and you write a padding operator to make 10px
borders for the images, then your output shape will be (234,234,3).
-* **forward**: This function executes the main forward computation. It takes
four arguments. The 1st argument is the attributes. The 2nd argument is the
input `MXTensors` which stores all data and info of input ndarrays. The 3rd
argument is the output `MXTensors`. The 4th argument is the `OpResource` object
for memory allocation and other utilities. Additionally, you can use a
`dltensor` tensor structure stored in the `MXTensor` as a more standardized
data structure for computing.
+* **forward**: This function executes the main forward computation. It takes
four arguments. The 1st argument is the attributes. The 2nd argument is the
input `MXTensors` which stores all data and info of input ndarrays. The 3rd
argument is the output `MXTensors`. The 4th argument is the `OpResource` object
for memory allocation and other utilities. The details of `OpResource` are
covered in the below section.
+Additionally, you can use a `dltensor` tensor structure stored in the
`MXTensor` as a more standardized data structure for computing.
* **backward**: This function is doing the backward gradient computation. It
will be similar to the forward function. And you need to figure out the formula
of the backward gradient computation.
* **mutateInputs**: This function is for marking mutable inputs. It takes two
arguments. The 1st argument is the attributes. The 2nd argument is a list of
input indices that are mutable among all input tensors. It is useful when some
inputs are auxiliary model parameters and might be altered during
forward/backward computation. Remember, the index number of `input_indices`
should not exceed the number of inputs.
-### Writing Stateful Custom Operator:
+### Writing Stateful Custom Operator
A stateful custom operator is useful when a forward/backward call needs some
data or ‘state’ from previous forward/backward calls. Normally we create a
class, and make instance variables store the states used for computing or
caching.
Most of the building blocks for making a stateful custom operator is the same
as regular custom operator, except it’ll register `createOpState` instead of a
`forward` function for the computation.
* [createOpState](./gemm_lib.cc#L204) - Create stateful operator instance:
* This function takes two arguments. The 1st argument is attributes. The
2nd argument is a placeholder for `CustomStatefulOp` object. You must [define a
class that inherits CustomStatefulOp](./gemm_lib.cc#L178) and override the
forward function (optionally the backward function). Then you need to create an
instance of your class and assign it to the placeholder. In this way, all of
the forward/backward calls will use the same methods in that instance, and the
instance is able to keep the state of the operator.
+```c++
Review comment:
```suggestion
```c++
```
give it some space
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services