Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
140ef0b4
提交
140ef0b4
authored
8月 29, 2014
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add documentation for the _struct() c_code functions.
上级
d030b654
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
101 行增加
和
29 行删除
+101
-29
cop.txt
doc/extending/cop.txt
+101
-29
没有找到文件。
doc/extending/cop.txt
浏览文件 @
140ef0b4
...
@@ -31,43 +31,82 @@ There are less methods to define for an Op than for a Type:
...
@@ -31,43 +31,82 @@ There are less methods to define for an Op than for a Type:
.. method:: c_code(node, name, input_names, output_names, sub)
.. method:: c_code(node, name, input_names, output_names, sub)
This must return C code that carries the computation we want to do.
This must return C code that carries the computation we want to
do.
sub is a dictionary of strings for you to substitute into your code.
`sub` is a dictionary of extras parameters to the c_code
It's not clear if it ever contains anything other than 'fail'.
method. It contains the following values:
sub['fail'] is a string of code that you should execute (after calling
PyErr_Format) if your C code needs to raise an exception.
``sub['fail']``
A string of code that you should execute (after ensuring
that a python exception is set) if your C code needs to
raise an exception.
``sub['struct_id']``
The integer id passed to the various _struct methods.
.. method:: c_code_cleanup(node, name, input_names, output_names, sub)
.. method:: c_code_cleanup(node, name, input_names, output_names, sub)
This must return C code that cleans up whatever c_code allocated and
This must return C code that cleans up whatever c_code
that we must free.
allocated and
that we must free.
*Default:* The default behavior is to do nothing.
*Default:* The default behavior is to do nothing.
.. method:: c_headers()
.. method:: c_headers()
Returns a list of headers to include in the file. 'Python.h' is
included by default so you don't need to specify it. Also all
of the header required by the Types involved (inputs and
outputs) will also be included.
.. method:: c_header_dirs()
.. method:: c_header_dirs()
Returns a list of directories to search for headers (arguments
to -I).
.. method:: c_libraries()
.. method:: c_libraries()
Returns a list of library names that your op needs to link to.
All ops are automatically linked with 'python' and the
libraries their types require. (arguments to -l)
.. method:: c_lib_dirs()
.. method:: c_lib_dirs()
Allows you to specify headers, libraries, and their directories,
Returns a list of directory to search for libraries (arguments
to -L).
.. method:: c_compile_args()
.. method:: c_compile_args()
Allows to specify additional arbitrary arguments to g++. This
is not usually required.
.. method:: c_no_compile_args()
.. method:: c_no_compile_args()
Allows you to specify special g++ arguments to add/exclude
Returns a list of g++ arguments that are forbidden when
compiling this Op.
.. method:: c_init_code()
.. method:: c_init_code()
Allows you to specify code that will be executed once when the
Allows you to specify code that will be executed once when the
module is initialized, before anything else is executed.
module is initialized, before anything else is executed. This
is for code that will be executed once per Op.
.. method:: c_init_code_apply(
self,
node, name)
.. method:: c_init_code_apply(node, name)
Allows you to specify code that will be executed once when the
Allows you to specify code that will be executed once when the
module is initialized, before anything else is executed and is
module is initialized, before anything else is executed and is
specialized for a particular apply of an :ref:`op`. Use
specialized for a particular apply of an :ref:`op`.
`c_init_code` if the code is the same for each apply of an op.
.. method:: c_init_code_struct(node, struct_id)
Allows you to specify code that will be inserted in the struct
constructor of the Op. This is for code which should be
executed once per thunk (Apply node, more or less).
`struct_id` is an integer guaranteed to be unique inside the
struct.
.. method:: c_support_code()
.. method:: c_support_code()
...
@@ -77,30 +116,63 @@ There are less methods to define for an Op than for a Type:
...
@@ -77,30 +116,63 @@ There are less methods to define for an Op than for a Type:
.. method:: c_support_code_apply(node, name)
.. method:: c_support_code_apply(node, name)
Allows you to specify helper functions/structs specialized for a
Allows you to specify helper functions/structs specialized for
particular apply of an :ref:`op`. Use `c_support_code` if the
a particular apply of an :ref:`op`. Use :meth:`c_support_code`
code is the same for each apply of an op.
if the code is the same for each apply of an op. It will be
It will be inserted at global scope.
inserted at global scope.
.. method:: c_support_code_struct(node, struct_id)
Allows you to specify helper functions of variables that will
be specific to one particular thunk. These are inserted at
struct scope.
`struct_id` is an integer guaranteed to be unique inside the
struct.
:note:
You cannot specify kernels in the code returned by this since
that isn't supported by CUDA. You should place your kernels
in :meth:`c_support_code()` or :meth:`c_support_code_apply()`
and call them from this code.
.. method:: c_cleanup_code_struct(node, struct_id)
Allows you to specify code that will be inserted in the struct
destructor of the Op. This is for cleaninp up allocations and
stuff like this when the thunk is released (when you "free" a
compiled function using this op).
`struct_id` is an integer guaranteed to be unique inside the
struct.
.. method:: infer_shape(node, (i0_shapes,i1_shapes,...))
.. method:: infer_shape(node, (i0_shapes,i1_shapes,...))
Allow optimizations to lift the Shape op over this op.
Allow optimizations to lift the Shape op over this op. An
An example of why this is good is when we only need the shape of a
example of why this is good is when we only need the shape of a
variable: we will be able to obtain it without computing the variable
variable: we will be able to obtain it without computing the
itself.
variable itself.
Must return a list where each element is a tuple representing the shape
of one output.
Must return a list where each element is a tuple representing
For example, for the matrix-matrix product ``infer_shape`` will have as
the shape of one output.
inputs (node, ((x0,x1), (y0,y1))) and should return [(x0, y1)]. Both the
inputs and the return value may be Theano variables.
For example, for the matrix-matrix product ``infer_shape`` will
have as inputs (node, ((x0,x1), (y0,y1))) and should return
[(x0, y1)]. Both the inputs and the return value may be Theano
variables.
.. method:: c_code_cache_version()
.. method:: c_code_cache_version()
Should
return a tuple of hashable objects like integers. This
Must
return a tuple of hashable objects like integers. This
specifies the version of the code. It is used to cache the
specifies the version of the code. It is used to cache the
compiled code. You MUST change the returned tuple for each
compiled code. You MUST change the returned tuple for each
change in the code. If you don't want to cache the compiled code
change in the code. If you don't want to cache the compiled
return an empty tuple or don't implement it.
code return an empty tuple or don't implement it.
.. method:: c_code_cache_version_apply(node)
Overrides :meth:`c_code_cache_version` if defined, but
otherwise has the same contract.
The ``name`` argument is currently given an invalid value, so steer
The ``name`` argument is currently given an invalid value, so steer
away from it. As was the case with Type, ``sub['fail']`` provides
away from it. As was the case with Type, ``sub['fail']`` provides
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论