Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gemm as an operator #47

Merged
merged 3 commits into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions docs/Operators.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Operator Schemas
*This file is automatically generated from the [def files](/onnx/defs)*
* **Abs**

Absolute takes one input data (Tensor<T>) and produces one output data
Expand Down Expand Up @@ -280,7 +281,7 @@
<dt>X</dt>
<dd>Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image.Otherwise the size is (N x D1 x D2 ... x Dn)</dd>
<dt>weights</dt>
<dd>The weight tensor that will be used in the convolutions; has size (M x C x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C x k1 x k2 x ... x kn), where is the dimenstion of the kernel</dd>
<dd>The weight tensor that will be used in the convolutions; has size (M x C x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C x k1 x k2 x ... x kn), where is the dimension of the kernel</dd>
</dl>
* **output**:
<dl>
Expand Down Expand Up @@ -311,7 +312,7 @@
<dt>X</dt>
<dd>Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image.Otherwise the size is (N x D1 x D2 ... x Dn)</dd>
<dt>weights</dt>
<dd>The weight tensor that will be used in the convolutions; has size (C x M x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (C x M x k1 x k2 x ... x kn), where is the dimenstion of the kernel</dd>
<dd>The weight tensor that will be used in the convolutions; has size (C x M x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (C x M x k1 x k2 x ... x kn), where is the dimension of the kernel</dd>
</dl>
* **output**:
<dl>
Expand Down Expand Up @@ -459,7 +460,7 @@
* **output**:
<dl>
<dt>output</dt>
<dd>A tensor of rank 2 with the contents of the input tensor, with first dimension equal first dimension of input, and remaining input dimensions flatenned into the inner dimension of the output.</dd>
<dd>A tensor of rank 2 with the contents of the input tensor, with first dimension equal first dimension of input, and remaining input dimensions flattened into the inner dimension of the output.</dd>
</dl>


Expand Down Expand Up @@ -520,6 +521,39 @@
</dl>


* **Gemm**

General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3
Compute Y = alpha * A * B + beta * C, where input tensor A has dimension (M X K), input tensor B has dimension (K X N), input tensor C and output tensor Y have dimension (M X N). Input tensor C can be used inplace as the output tensor Y. If attribute broadcast is non-zero, input tensor C will be broadcasted to match the dimension requirement. If A can be transposed before doing the computation if attribute transA is non-zero, same for B and transB.
* **attribute**:
<dl>
<dt>alpha</dt>
<dd>Scalar multiplier for the product of input tensors A * B</dd>
<dt>beta</dt>
<dd>Scalar multiplier for input tensor C</dd>
<dt>broadcast</dt>
<dd>Whether C should be broadcasted</dd>
<dt>transA</dt>
<dd>Whether A should be transposed</dd>
<dt>transB</dt>
<dd>Whether B should be transposed</dd>
</dl>
* **input**:
<dl>
<dt>A</dt>
<dd>Input tensor A</dd>
<dt>B</dt>
<dd>Input tensor B</dd>
<dt>C</dt>
<dd>Input tensor C, can be inplace.</dd>
</dl>
* **output**:
<dl>
<dt>Y</dt>
<dd>Output tensor.</dd>
</dl>


* **GlobalAveragePool**

GlobalAveragePool consumes an input tensor X and applies average pooling across the
Expand Down
2 changes: 1 addition & 1 deletion onnx/defs/gen_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def display_number(v):

def main(args):
args.output.write('## Operator Schemas\n')
args.output.write('*This file is automatically generated from the [def files](/onnx/defs)*')
args.output.write('*This file is automatically generated from the [def files](/onnx/defs)*\n')

for op_type, schema in sorted(defs.get_all_schemas().items()):
# If support level is experimental, then don't generate documentation.
Expand Down
27 changes: 27 additions & 0 deletions onnx/defs/math/defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,30 @@ will throw errors.
"as described above.")
.Output(0, "output", "The softmax normalized output values with the same "
"shape as input tensor.");

OPERATOR_SCHEMA(Gemm)
.NumInputs(3)
.NumOutputs(1)
.SetDoc(R"DOC(General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3
Compute Y = alpha * A * B + beta * C, where input tensor A has dimension (M X K), input tensor B has dimension (K X N), input tensor C and output tensor Y have dimension (M X N). Input tensor C can be used inplace as the output tensor Y. If attribute broadcast is non-zero, input tensor C will be broadcasted to match the dimension requirement. If A can be transposed before doing the computation if attribute transA is non-zero, same for B and transB.
)DOC")
.Input(0, "A", "Input tensor A")
.Input(1, "B", "Input tensor B")
.Input(2, "C", "Input tensor C, can be inplace.")
.AllowConsumed({{2, 0}})
.Output(0, "Y", "Output tensor.")
.Attr("transA",
"Whether A should be transposed",
AttrType::INT)
.Attr("transB",
"Whether B should be transposed",
AttrType::INT)
.Attr("broadcast",
"Whether C should be broadcasted",
AttrType::INT)
.Attr("alpha",
"Scalar multiplier for the product of input tensors A * B",
AttrType::FLOAT)
.Attr("beta",
"Scalar multiplier for input tensor C",
AttrType::FLOAT);