Skip to content

Commit

Permalink
add docs for ops
Browse files Browse the repository at this point in the history
  • Loading branch information
antkillerfarm authored and thezha committed May 21, 2021
1 parent a85fe89 commit 3339135
Show file tree
Hide file tree
Showing 35 changed files with 444 additions and 5 deletions.
7 changes: 5 additions & 2 deletions docs/gen_docs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
import sys
import os
from markdown_toclify import markdown_toclify

root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
src_dir = root_dir + "/include/tim/vx/ops"
Expand Down Expand Up @@ -73,4 +73,7 @@ def get_md_blocks(file):
with open(root_dir + md_file, mode='w',newline='\n', encoding='UTF-8') as fhndl:
fhndl.writelines(new_lines)

print(root_dir)
cont = markdown_toclify(input_file=root_dir + md_file)

with open(root_dir + md_file, mode='w',newline='\n', encoding='UTF-8') as fhndl:
fhndl.write(cont)
2 changes: 1 addition & 1 deletion include/tim/vx/ops/activations.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace ops {
* LeakyRelu(x) : alpha * x if x <= 0; x if x > 0. alpha is a scalar.
*
* Prelu(x) : alpha * x if x <= 0; x if x > 0. alpha is a tensor.
* - axis : Describes the axis of the inputs when coerced to 2D.
* - axis : describes the axis of the inputs when coerced to 2D.
* ```
*/

Expand Down
2 changes: 1 addition & 1 deletion include/tim/vx/ops/batch2space.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace ops {
* This operation reshapes the batch dimension (dimension 0) into M + 1 dimensions
* of shape **block_size** + [batch], interleaves these blocks back into the grid
* defined by the spatial dimensions [1, ..., M], to obtain a result with the same
* rank as the input.
* rank as the input. This is the reverse transformation of Space2Batch.
*
* - crop : corp the output tensor for ROI usage.
*/
Expand Down
1 change: 1 addition & 0 deletions include/tim/vx/ops/concat.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace ops {
* ## Concat
*
* Concatenate a list of tensors into a single tensor.
*
* - axis : Which axis to concat on.
*/

Expand Down
2 changes: 1 addition & 1 deletion include/tim/vx/ops/conv2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace ops {
* Performs a 2-D convolution operation, include classic Conv2D /
* Depthwise Conv2D / Group Conv2D / Dilation Conv2D.
*
* - weights : the channel number for weight tensor.
* - weights : the output channel number for weight tensor.
* - ksize : the height and width for weight tensor.
* - padding : AUTO, VALID or SAME.
* - pad : pad value for each spatial axis.
Expand Down
16 changes: 16 additions & 0 deletions include/tim/vx/ops/depth2space.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## DepthToSpace
*
* DepthToSpace rearranges (permutes) data from depth into blocks of spatial data.
* This is the reverse transformation of SpaceToDepth.
*
* Chunks of data of size block_size * block_size from depth are rearranged into
* non-overlapping blocks of size block_size x block_size.
*
* The width of the output tensor is input_depth * block_size, whereas the height
* is input_height * block_size. The depth of the input tensor must be divisible
* by block_size * block_size
*
* - crop : corp the output tensor for ROI usage.
*/

class DepthToSpace : public Operation {
public:
DepthToSpace(Graph* Graph, int block_size,
Expand Down
9 changes: 9 additions & 0 deletions include/tim/vx/ops/dropout.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## Dropout
*
* The Dropout layer randomly sets input units to 0 with a frequency of rate at
* each step during training time, which helps prevent overfitting.
*
* TIM-VX only focus on inference time, and just scaling input tensor by **ratio**
* for Dropout operator.
*/

class Dropout : public Operation {
public:
Expand Down
33 changes: 33 additions & 0 deletions include/tim/vx/ops/elementwise.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## Add
*
* Add(x, y) : x + y. This operation supports broadcasting.
*
* ## Sub
*
* Sub(x, y) : x - y. This operation supports broadcasting.
*
* ## Multiply
*
* Multiply(x, y) : Multiplies two tensors, element-wise, also known as Hadamard
* product. This operation supports broadcasting.
*
* - scale: scaling the product.
*
* ## Div
*
* Div(x, y) : x / y. This operation supports broadcasting.
*
* ## Pow
*
* Pow(x, y) : x ^ y. This operation supports broadcasting.
*
* ## Minimum
*
* Minimum(x, y) : min(x, y). This operation supports broadcasting.
*
* ## Maximum
*
* Maximum(x, y) : max(x, y). This operation supports broadcasting.
*/

#define DECLARE_ELEMENTWISE_OP(NAME) \
class NAME : public Operation { \
public: \
Expand Down
11 changes: 11 additions & 0 deletions include/tim/vx/ops/fullyconnected.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
namespace tim {
namespace vx {
namespace ops {

/**
* ## FullyConnected
*
* Denotes a fully (densely) connected layer, which connects all elements in the
* input tensor with each element in the output tensor.
*
* - axis: Describes the axis of the inputs when coerced to 2D.
* - weights: the output channel number for weight tensor.
*/

class FullyConnected : public Operation {
public:
FullyConnected(Graph* graph, uint32_t axis, uint32_t weights);
Expand Down
6 changes: 6 additions & 0 deletions include/tim/vx/ops/gather.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## Gather
*
* Gather slices from input, **axis** according to **indices**.
*/

class Gather : public Operation {
public:
Gather(Graph* Graph, int axis);
Expand Down
6 changes: 6 additions & 0 deletions include/tim/vx/ops/gathernd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## GatherNd
*
* An operation similar to Gather but gathers across multiple axis at once.
*/

class GatherNd : public Operation {
public:
GatherNd(Graph* Graph);
Expand Down
12 changes: 12 additions & 0 deletions include/tim/vx/ops/l2normalization.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
#define TIM_VX_OPS_L2NOMALIZATION_H_
#include "tim/vx/operation.h"

/**
* ## L2Normalization
*
* Applies L2 normalization along the axis dimension:
*
* ```
* output[batch, row, col, channel] =
* input[batch, row, col, channel] /
* sqrt(sum_{c} pow(input[batch, row, col, c], 2))
* ```
*/

namespace tim {
namespace vx {
namespace ops {
Expand Down
12 changes: 12 additions & 0 deletions include/tim/vx/ops/localresponsenormalization.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
#define TIM_VX_OPS_LOCALRESPONSENORMALIZATION_H_
#include "tim/vx/operation.h"

/**
* ## LocalResponseNormalization
*
* Applies Local Response Normalization along the depth dimension:
*
* ```
* sqr_sum[a, b, c, d] = sum(
* pow(input[a, b, c, d - depth_radius : d + depth_radius + 1], 2))
* output = input / pow((bias + alpha * sqr_sum), beta)
* ```
*/

namespace tim {
namespace vx {
namespace ops {
Expand Down
10 changes: 10 additions & 0 deletions include/tim/vx/ops/logical.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## And
*
* Returns the truth value of x AND y element-wise. This operation supports broadcasting.
*
* ## Or
*
* Returns the truth value of x OR y element-wise. This operation supports broadcasting.
*/

#define DECLARE_LOGICAL_OP(NAME) \
class Logical##NAME : public Operation { \
public: \
Expand Down
7 changes: 7 additions & 0 deletions include/tim/vx/ops/nbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## NBG
*
* Network Binary Graph is a precompile technology, which can compile a fuse graph into
* a bianry file.
*/

class NBG : public Operation {
public:
NBG(Graph* graph, const char* binary, size_t input_count, size_t output_count);
Expand Down
9 changes: 9 additions & 0 deletions include/tim/vx/ops/pad.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
namespace tim {
namespace vx {
namespace ops {

/**
* ## Pad
*
* Pads a tensor.
*
* - const_val : the value to pad.
*/

class Pad : public Operation {
public:
Pad(Graph* graph, const std::vector<uint32_t>& front_size,
Expand Down
12 changes: 12 additions & 0 deletions include/tim/vx/ops/pool2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## Pool2d
*
* Performs an 2-D pooling operation.
*
* - type : MAX, AVG, L2 or AVG_ANDROID.
* - padding : AUTO, VALID or SAME.
* - ksize : filter size.
* - stride : stride along each spatial axis.
* - round_type : CEILING or FLOOR.
*/

class Pool2d : public Operation {
public:
Pool2d(Graph* graph, PoolType type, PadType padding,
Expand Down
66 changes: 66 additions & 0 deletions include/tim/vx/ops/reduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,71 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## ReduceMin
*
* Reduces a tensor by computing the minimum of elements along given dimensions.
*
* - axis : the dimensions to reduce.
* - keep_dims : If keep_dims is true, the reduced dimensions are retained with
* length 1. Otherwise, the rank of the tensor is reduced by 1 for each entry
* in dimensions
*
* ## ReduceMax
*
* Reduces a tensor by computing the maximum of elements along given dimensions.
*
* - axis : the dimensions to reduce.
* - keep_dims : If keep_dims is true, the reduced dimensions are retained with
* length 1. Otherwise, the rank of the tensor is reduced by 1 for each entry
* in dimensions
*
* ## ReduceAny
*
* Reduces a tensor by computing the "logical or" of elements along given dimensions.
*
* - axis : the dimensions to reduce.
* - keep_dims : If keep_dims is true, the reduced dimensions are retained with
* length 1. Otherwise, the rank of the tensor is reduced by 1 for each entry
* in dimensions
*
* ## ReduceAll
*
* Reduces a tensor by computing the "logical and" of elements along given dimensions.
*
* - axis : the dimensions to reduce.
* - keep_dims : If keep_dims is true, the reduced dimensions are retained with
* length 1. Otherwise, the rank of the tensor is reduced by 1 for each entry
* in dimensions
*
* ## ReduceProd
*
* Reduces a tensor by computing the multiplying of elements along given dimensions.
*
* - axis : the dimensions to reduce.
* - keep_dims : If keep_dims is true, the reduced dimensions are retained with
* length 1. Otherwise, the rank of the tensor is reduced by 1 for each entry
* in dimensions
*
* ## ReduceMean
*
* Reduces a tensor by computing the mean of elements along given dimensions.
*
* - axis : the dimensions to reduce.
* - keep_dims : If keep_dims is true, the reduced dimensions are retained with
* length 1. Otherwise, the rank of the tensor is reduced by 1 for each entry
* in dimensions
*
* ## ReduceSum
*
* Reduces a tensor by computing the summing of elements along given dimensions.
*
* - axis : the dimensions to reduce.
* - keep_dims : If keep_dims is true, the reduced dimensions are retained with
* length 1. Otherwise, the rank of the tensor is reduced by 1 for each entry
* in dimensions
*/

#define DECLARE_REDUCE_OP(NAME) \
class Reduce##NAME : public Operation { \
public: \
Expand All @@ -43,6 +108,7 @@ namespace ops {
DECLARE_REDUCE_OP(Min);
DECLARE_REDUCE_OP(Max);
DECLARE_REDUCE_OP(Any);
DECLARE_REDUCE_OP(All);
DECLARE_REDUCE_OP(Prod);
DECLARE_REDUCE_OP(Mean);
DECLARE_REDUCE_OP(Sum);
Expand Down
26 changes: 26 additions & 0 deletions include/tim/vx/ops/relational_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ namespace tim {
namespace vx {
namespace ops {

/**
* ## Greater
*
* For input tensors x and y, computes x > y elementwise.
*
* ## GreaterOrEqual
*
* For input tensors x and y, computes x >= y elementwise.
*
* ## Less
*
* For input tensors x and y, computes x < y elementwise.
*
* ## LessOrEqual
*
* For input tensors x and y, computes x <= y elementwise.
*
* ## NotEqual
*
* For input tensors x and y, computes x != y elementwise.
*
* ## Equal
*
* For input tensors x and y, computes x == y elementwise.
*/

#define DECLARE_RELATIONAL_OP(NAME) \
class NAME : public Operation { \
public: \
Expand Down
Loading

0 comments on commit 3339135

Please sign in to comment.