Skip to content

Commit

Permalink
新文件: doc/dev/TODOs.md
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxinwei committed Jun 6, 2024
1 parent a749d71 commit 7bb495e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 212 deletions.
3 changes: 3 additions & 0 deletions doc/dev/TODOs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 待办事项

- [ ] 阅读 [8-bit Inference with TensorRT](https://on-demand.gputechconf.com/gtc/2017/presentation/s7310-8-bit-inference-with-tensorrt.pdf)
1 change: 1 addition & 0 deletions doc/dev/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

```{toctree}
TODOs
news
cpp-book <https://xinetzone.github.io/cpp-book>
```
168 changes: 33 additions & 135 deletions doc/tutorials/intro/packed-func.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import set_env"
"import testing"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -65,7 +65,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -202,20 +202,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tvm.ir.container.Array"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"a = tvm.runtime.convert([1, 2, 3])\n",
"assert len(a) == 3\n",
Expand All @@ -234,7 +223,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -254,20 +243,9 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tvm.ir.container.Map"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"amap = tvm.runtime.convert({\"a\": 2, \"b\": 3})\n",
"type(amap)"
Expand All @@ -282,20 +260,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[runtime.NDArray(0x9cbd970), runtime.NDArray(0x9cbd970)]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = tvm.nd.array([1, 2, 3])\n",
"arr = tvm.runtime.convert([x, x])\n",
Expand All @@ -304,27 +271,16 @@
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<tvm.runtime.packed_func.PackedFunc at 0x7f0a04db14d0>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tvm.runtime.convert(f)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -340,7 +296,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -360,7 +316,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -393,7 +349,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -417,7 +373,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -443,7 +399,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -481,7 +437,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -512,7 +468,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -541,40 +497,9 @@
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div class=\"highlight\" style=\"background: \"><pre style=\"line-height: 125%;\"><span></span><span style=\"color: #007979; font-style: italic\"># from tvm.script import tir as T</span>\n",
"\n",
"<span style=\"color: #AA22FF\">@T</span><span style=\"color: #AA22FF; font-weight: bold\">.</span>prim_func\n",
"<span style=\"color: #008000; font-weight: bold\">def</span> <span style=\"color: #0000FF\">main</span>(var_A: T<span style=\"color: #AA22FF; font-weight: bold\">.</span>handle, var_C: T<span style=\"color: #AA22FF; font-weight: bold\">.</span>handle):\n",
" T<span style=\"color: #AA22FF; font-weight: bold\">.</span>func_attr({<span style=\"color: #BA2121\">&quot;tir.noalias&quot;</span>: T<span style=\"color: #AA22FF; font-weight: bold\">.</span>bool(<span style=\"color: #008000; font-weight: bold\">True</span>)})\n",
" A <span style=\"color: #AA22FF; font-weight: bold\">=</span> T<span style=\"color: #AA22FF; font-weight: bold\">.</span>match_buffer(var_A, (<span style=\"color: #008000\">10</span>,), offset_factor<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #008000\">1</span>)\n",
" C <span style=\"color: #AA22FF; font-weight: bold\">=</span> T<span style=\"color: #AA22FF; font-weight: bold\">.</span>match_buffer(var_C, (<span style=\"color: #008000\">10</span>,), offset_factor<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #008000\">1</span>)\n",
" <span style=\"color: #008000; font-weight: bold\">with</span> T<span style=\"color: #AA22FF; font-weight: bold\">.</span>block(<span style=\"color: #BA2121\">&quot;C&quot;</span>):\n",
" T<span style=\"color: #AA22FF; font-weight: bold\">.</span>reads()\n",
" T<span style=\"color: #AA22FF; font-weight: bold\">.</span>writes()\n",
" T<span style=\"color: #AA22FF; font-weight: bold\">.</span>call_packed(<span style=\"color: #BA2121\">&quot;tvm.contrib.my_tvm_addone&quot;</span>, T<span style=\"color: #AA22FF; font-weight: bold\">.</span>tvm_stack_make_array(A<span style=\"color: #AA22FF; font-weight: bold\">.</span>data, T<span style=\"color: #AA22FF; font-weight: bold\">.</span>tvm_stack_make_shape(<span style=\"color: #008000\">10</span>), <span style=\"color: #008000\">0</span>, <span style=\"color: #008000\">1</span>, T<span style=\"color: #AA22FF; font-weight: bold\">.</span>float32(<span style=\"color: #008000\">0</span>), A<span style=\"color: #AA22FF; font-weight: bold\">.</span>elem_offset), T<span style=\"color: #AA22FF; font-weight: bold\">.</span>tvm_stack_make_array(C<span style=\"color: #AA22FF; font-weight: bold\">.</span>data, T<span style=\"color: #AA22FF; font-weight: bold\">.</span>tvm_stack_make_shape(<span style=\"color: #008000\">10</span>), <span style=\"color: #008000\">0</span>, <span style=\"color: #008000\">1</span>, T<span style=\"color: #AA22FF; font-weight: bold\">.</span>float32(<span style=\"color: #008000\">0</span>), C<span style=\"color: #AA22FF; font-weight: bold\">.</span>elem_offset))\n",
"</pre></div>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"my_tvm_addone signatures: <class 'tvm.runtime.ndarray.NDArray'>, <class 'tvm.runtime.ndarray.NDArray'>\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from tvm import te\n",
Expand Down Expand Up @@ -617,7 +542,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -640,36 +565,9 @@
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div class=\"highlight\" style=\"background: \"><pre style=\"line-height: 125%;\"><span></span><span style=\"color: #007979; font-style: italic\"># from tvm.script import tir as T</span>\n",
"\n",
"<span style=\"color: #AA22FF\">@T</span><span style=\"color: #AA22FF; font-weight: bold\">.</span>prim_func\n",
"<span style=\"color: #008000; font-weight: bold\">def</span> <span style=\"color: #0000FF\">main</span>(X: T<span style=\"color: #AA22FF; font-weight: bold\">.</span>Buffer((<span style=\"color: #008000\">137</span>, <span style=\"color: #008000\">137</span>), <span style=\"color: #BA2121\">&quot;float32&quot;</span>), Y: T<span style=\"color: #AA22FF; font-weight: bold\">.</span>Buffer((<span style=\"color: #008000\">137</span>, <span style=\"color: #008000\">137</span>), <span style=\"color: #BA2121\">&quot;float32&quot;</span>), compute: T<span style=\"color: #AA22FF; font-weight: bold\">.</span>Buffer((<span style=\"color: #008000\">137</span>, <span style=\"color: #008000\">137</span>), <span style=\"color: #BA2121\">&quot;float32&quot;</span>)):\n",
" T<span style=\"color: #AA22FF; font-weight: bold\">.</span>func_attr({<span style=\"color: #BA2121\">&quot;tir.noalias&quot;</span>: T<span style=\"color: #AA22FF; font-weight: bold\">.</span>bool(<span style=\"color: #008000; font-weight: bold\">True</span>)})\n",
" <span style=\"color: #007979; font-style: italic\"># with T.block(&quot;root&quot;):</span>\n",
" <span style=\"color: #008000; font-weight: bold\">for</span> i, j, k <span style=\"color: #008000; font-weight: bold\">in</span> T<span style=\"color: #AA22FF; font-weight: bold\">.</span>grid(<span style=\"color: #008000\">137</span>, <span style=\"color: #008000\">137</span>, <span style=\"color: #008000\">137</span>):\n",
" <span style=\"color: #008000; font-weight: bold\">with</span> T<span style=\"color: #AA22FF; font-weight: bold\">.</span>block(<span style=\"color: #BA2121\">&quot;compute&quot;</span>):\n",
" v_i, v_j, v_k <span style=\"color: #AA22FF; font-weight: bold\">=</span> T<span style=\"color: #AA22FF; font-weight: bold\">.</span>axis<span style=\"color: #AA22FF; font-weight: bold\">.</span>remap(<span style=\"color: #BA2121\">&quot;SSR&quot;</span>, [i, j, k])\n",
" T<span style=\"color: #AA22FF; font-weight: bold\">.</span>reads(X[v_i, v_k], Y[v_k, v_j])\n",
" T<span style=\"color: #AA22FF; font-weight: bold\">.</span>writes(compute[v_i, v_j])\n",
" <span style=\"color: #008000; font-weight: bold\">with</span> T<span style=\"color: #AA22FF; font-weight: bold\">.</span>init():\n",
" compute[v_i, v_j] <span style=\"color: #AA22FF; font-weight: bold\">=</span> T<span style=\"color: #AA22FF; font-weight: bold\">.</span>float32(<span style=\"color: #008000\">0</span>)\n",
" compute[v_i, v_j] <span style=\"color: #AA22FF; font-weight: bold\">=</span> compute[v_i, v_j] <span style=\"color: #AA22FF; font-weight: bold\">+</span> X[v_i, v_k] <span style=\"color: #AA22FF; font-weight: bold\">*</span> Y[v_k, v_j]\n",
"</pre></div>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def tvm_func(n):\n",
" XX = te.placeholder((n, n), name=\"X\")\n",
Expand All @@ -685,7 +583,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down
Loading

0 comments on commit 7bb495e

Please sign in to comment.