generated from xinetzone/sphinx-demo
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liuxinwei
committed
May 8, 2024
1 parent
96067c8
commit 3ccd620
Showing
50 changed files
with
2,231 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ temp/ | |
*.json | ||
.temp/ | ||
api/ | ||
.temp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# VTA 教程 | ||
# VTA 教程(chaos) | ||
|
||
官方教程见:[VTA](https://xinetzone.github.io/tvm/docs/topic/vta/index.html)。 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ te/index | |
topi/index | ||
tir/index | ||
op/index | ||
layout/index | ||
attrs/index | ||
expr/index | ||
reflection | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# InferCorrectLayoutOutput" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import set_env" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import tvm\n", | ||
"from tvm import relay\n", | ||
"from tvm.relay.testing.temp_op_attr import TempOpAttr\n", | ||
"from tvm.relay.op import op as _op" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"op_name = \"custom_op\"\n", | ||
"\n", | ||
"_op.register(op_name, r\"code(Add two tensor with inner broadcasting.)code\")\n", | ||
"_op.get(op_name).set_num_inputs(2)\n", | ||
"_op.get(op_name).add_argument(\"data_0\", \"Tensor\", \"The input data tensor.\")\n", | ||
"_op.get(op_name).add_argument(\"data_1\", \"Tensor\", \"The input data tensor.\")\n", | ||
"# 调用默认关系函数\n", | ||
"_op.get(op_name).add_type_rel(\"Identity\")\n", | ||
"_op.get(op_name).set_support_level(1)\n", | ||
"_op.register_pattern(op_name, _op.OpPattern.ELEMWISE)\n", | ||
"_op.register_stateful(op_name, False)\n", | ||
"\n", | ||
"assert _op.get(op_name).name == op_name\n", | ||
"assert _op.get(op_name).num_inputs == 2\n", | ||
"assert _op.get(op_name).get_attr(\"TOpPattern\") == _op.OpPattern.ELEMWISE\n", | ||
"assert _op.get(op_name).get_attr(\"TOpIsStateful\") == False" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\u001b[0;31mSignature:\u001b[0m \u001b[0m_op\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mregister_infer_correct_layout\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mop_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfer_layout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;31mSource:\u001b[0m \n", | ||
"\u001b[0;32mdef\u001b[0m \u001b[0mregister_infer_correct_layout\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mop_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfer_layout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", | ||
"\u001b[0;34m\u001b[0m \u001b[0;34m\"\"\"Register infer op layout function for an op\u001b[0m\n", | ||
"\u001b[0;34m\u001b[0m\n", | ||
"\u001b[0;34m Parameters\u001b[0m\n", | ||
"\u001b[0;34m ----------\u001b[0m\n", | ||
"\u001b[0;34m op_name : str\u001b[0m\n", | ||
"\u001b[0;34m The name of the operator\u001b[0m\n", | ||
"\u001b[0;34m\u001b[0m\n", | ||
"\u001b[0;34m infer_layout: function (attrs: Attrs, inputs: List[Layout]) -> InferCorrectLayoutOutput\u001b[0m\n", | ||
"\u001b[0;34m The function to infer correct layout\u001b[0m\n", | ||
"\u001b[0;34m\u001b[0m\n", | ||
"\u001b[0;34m level : int\u001b[0m\n", | ||
"\u001b[0;34m The priority level\u001b[0m\n", | ||
"\u001b[0;34m \"\"\"\u001b[0m\u001b[0;34m\u001b[0m\n", | ||
"\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mregister_op_attr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mop_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"FInferCorrectLayout\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfer_layout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;31mFile:\u001b[0m /media/pc/data/lxw/ai/tvm/python/tvm/relay/op/op.py\n", | ||
"\u001b[0;31mType:\u001b[0m function" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"_op.register_infer_correct_layout??" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"{func}`~tvm.relay.op.op.register_infer_correct_layout` 用于为算子注册推断布局函数。\n", | ||
"\n", | ||
"参数说明:\n", | ||
"- `op_name`:字符串类型,表示算子的名称。\n", | ||
"- `infer_layout`:函数类型,接受两个参数 `attrs` 和 `inputs`,返回 {class}`~tvm.relay.transform.infer_layout_utils.InferCorrectLayoutOutput` 类型的对象。该函数用于推断正确的布局。\n", | ||
"- `level`:整数类型,表示优先级级别。" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"<function __main__.infer_layout(attrs: tvm.ir.attrs.Attrs, inputs: list[tvm.tir.data_layout.Layout])>" | ||
] | ||
}, | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from tvm.relay.transform.infer_layout_utils import InferCorrectLayoutOutput\n", | ||
"from tvm.ir import Attrs\n", | ||
"from tvm.tir.data_layout import Layout\n", | ||
"\n", | ||
"def infer_layout(attrs: Attrs, inputs: list[Layout]):\n", | ||
" return InferCorrectLayoutOutput()\n", | ||
"_op.register_infer_correct_layout(op_name, infer_layout)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\u001b[0;31mInit signature:\u001b[0m \u001b[0mInferCorrectLayoutOutput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_layouts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput_layouts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnew_attrs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;31mDocstring:\u001b[0m An output structure to hold results from FInferCorrectLayout calls.\n", | ||
"\u001b[0;31mFile:\u001b[0m /media/pc/data/lxw/ai/tvm/python/tvm/relay/transform/infer_layout_utils.py\n", | ||
"\u001b[0;31mType:\u001b[0m type\n", | ||
"\u001b[0;31mSubclasses:\u001b[0m " | ||
] | ||
} | ||
], | ||
"source": [ | ||
"InferCorrectLayoutOutput?" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "xin", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# 数据布局 | ||
|
||
```{toctree} | ||
InferCorrectLayoutOutput | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from pathlib import Path | ||
from tvm_book.config.env import set_tvm | ||
TVM_ROOT = Path(__file__).resolve().parents[5] | ||
# TVM_ROOT = Path(__file__).resolve().parents[5] | ||
# print(TVM_ROOT) | ||
# TVM_ROOT = "/media/pc/data/lxw/ai/tvm/" | ||
TVM_ROOT = "/media/pc/data/lxw/ai/tvm/" | ||
set_tvm(TVM_ROOT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ | |
|
||
```{toctree} | ||
extension/index | ||
onnxscript/index | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ mxnet | |
tensorflow-tvm/index | ||
pytorch-tvm/index | ||
onnx-tvm/index | ||
onnxscript/index | ||
caffe-tvm/index | ||
relax-fx | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,4 @@ | |
onnx-format | ||
onnxruntime-start | ||
torch2onnx/index | ||
torch2onnx-test | ||
test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.