Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
aaf18388
提交
aaf18388
authored
10月 27, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address comments from review.
上级
4e7fcf8a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
32 行增加
和
11 行删除
+32
-11
using_params.txt
doc/extending/using_params.txt
+32
-11
没有找到文件。
doc/extending/using_params.txt
浏览文件 @
aaf18388
...
@@ -8,7 +8,7 @@ The Op params is a facility to pass some runtime parameters to the
...
@@ -8,7 +8,7 @@ The Op params is a facility to pass some runtime parameters to the
code of an op without modifying it. It can enable a single instance
code of an op without modifying it. It can enable a single instance
of C code to serve different needs and therefore reduce compilation.
of C code to serve different needs and therefore reduce compilation.
I
will first introduce the parts involved in actually using this
We
will first introduce the parts involved in actually using this
functionality and then present a simple working example.
functionality and then present a simple working example.
The params type
The params type
...
@@ -17,6 +17,19 @@ The params type
...
@@ -17,6 +17,19 @@ The params type
You can either reuse an existing type such as :class:`Generic` or
You can either reuse an existing type such as :class:`Generic` or
:class:`CDataType`, or create your own.
:class:`CDataType`, or create your own.
Using a python object for your op parameters (:class:`Generic`) can be
annoying to access from C code since you would have to go through the
Python-C API for all accesses.
Conversly, using a C struct (:class:`CDataType`) makes it complicated
to set values through python code, forcing you to go through ctypes or
other similar module.
Making a purpose-built class may require more upfront work, but can
pay off if you reuse the type for a lot of Ops, by making it easier to
manipulate from python and C.
Defining a params type
Defining a params type
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
...
@@ -41,16 +54,22 @@ following methods:
...
@@ -41,16 +54,22 @@ following methods:
- :meth:`c_extract <CLinkerType.c_extract>`
- :meth:`c_extract <CLinkerType.c_extract>`
- :meth:`c_cleanup <CLinkerType.c_cleanup>`
- :meth:`c_cleanup <CLinkerType.c_cleanup>`
You can also define other conv
i
nience methods such as
You can also define other conv
e
nience methods such as
:meth:`c_headers <CLinkerType.c_headers>` if you need any special things.
:meth:`c_headers <CLinkerType.c_headers>` if you need any special things.
Registering the params with your Op
Registering the params with your Op
-----------------------------------
-----------------------------------
To declare that your
o
p uses params you have to set the class
To declare that your
O
p uses params you have to set the class
attribute :attr:`params_type` to an instance of your params Type.
attribute :attr:`params_type` to an instance of your params Type.
.. note::
If you want to have multiple parameters you have to bundle those
inside a single object (or C struct) and use that as the params
type. Multiple types are not supported.
For example if we decide to use a pointer to an int as the params the
For example if we decide to use a pointer to an int as the params the
following would be appropriate:
following would be appropriate:
...
@@ -64,10 +83,9 @@ class with the following signature:
...
@@ -64,10 +83,9 @@ class with the following signature:
.. code-block:: python
.. code-block:: python
def get_params(self, node):
def get_params(self, node)
pass
This method
s
must return a valid object for your Type (an object that
This method must return a valid object for your Type (an object that
passes :meth:`filter`). The `node` parameter is the Apply node for
passes :meth:`filter`). The `node` parameter is the Apply node for
which we want the params. Therefore the params object can depend on
which we want the params. Therefore the params object can depend on
the inputs and outputs of the node.
the inputs and outputs of the node.
...
@@ -86,9 +104,9 @@ the inputs and outputs of the node.
...
@@ -86,9 +104,9 @@ the inputs and outputs of the node.
Signature changes from having params
Signature changes from having params
------------------------------------
------------------------------------
Having declared a params for you
Op will affect the expected signature
Having declared a params for you
r Op will affect the expected
of :meth:`perform`. The new expected signature will have an extra
signature of :meth:`perform`. The new expected signature will have an
parameter at the end which corresponds to the params object.
extra
parameter at the end which corresponds to the params object.
.. warning::
.. warning::
...
@@ -101,12 +119,15 @@ This is true for all methods that recieve a `sub` parameter, so this
...
@@ -101,12 +119,15 @@ This is true for all methods that recieve a `sub` parameter, so this
means that you can use your params in the :meth:`c_init_code_struct
means that you can use your params in the :meth:`c_init_code_struct
<Op.c_init_code_struct>` method.
<Op.c_init_code_struct>` method.
A simple example
A simple example
----------------
----------------
This is a simple example which uses a params object to pass a value.
This is a simple example which uses a params object to pass a value.
The value in this case is a python float, hence the choice of Generic
This Op will multiply a scalar input by a fixed floating point value.
as the params type.
Since the value in this case is a python float, we chose Generic as
the params type.
.. testcode::
.. testcode::
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论