Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
74138d60
提交
74138d60
authored
6月 20, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Prettify things and add a full example based on the tests.
上级
17712dfc
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
42 行增加
和
6 行删除
+42
-6
extending_theano_gpu.txt
doc/extending/extending_theano_gpu.txt
+39
-3
test_cgpukernelbase.py
theano/gpuarray/tests/test_cgpukernelbase.py
+3
-3
没有找到文件。
doc/extending/extending_theano_gpu.txt
浏览文件 @
74138d60
...
@@ -5,6 +5,10 @@
...
@@ -5,6 +5,10 @@
Extending Theano with a GPU Op
Extending Theano with a GPU Op
==============================
==============================
.. note::
This covers the :ref:`gpuarray <gpuarray>` back-end for the GPU.
This tutorial covers how to extend Theano with an op that offers a GPU
This tutorial covers how to extend Theano with an op that offers a GPU
implementation. It assumes you are familiar with how to write new
implementation. It assumes you are familiar with how to write new
Theano ops. If that is not the case you should probably follow the
Theano ops. If that is not the case you should probably follow the
...
@@ -15,7 +19,7 @@ Writing a new GPU op can be done in python for some simple tasks, but
...
@@ -15,7 +19,7 @@ Writing a new GPU op can be done in python for some simple tasks, but
will usually done in C to access the complete API and avoid paying the
will usually done in C to access the complete API and avoid paying the
overhead of a python function call.
overhead of a python function call.
Dealing
with the c
ontext
Dealing
With the C
ontext
========================
========================
One of the major differences with GPU ops is that they require a
One of the major differences with GPU ops is that they require a
...
@@ -82,7 +86,7 @@ the example of :class:`theano.gpuarray.basic_ops.GpuFromHost` or
...
@@ -82,7 +86,7 @@ the example of :class:`theano.gpuarray.basic_ops.GpuFromHost` or
:class:`theano.gpuarray.basic_ops.GpuEye`. This is not a case that
:class:`theano.gpuarray.basic_ops.GpuEye`. This is not a case that
you should encounter often, so it will not be covered further.
you should encounter often, so it will not be covered further.
Defining
new k
ernels
Defining
New K
ernels
====================
====================
If your op needs to do some transformation on the data, chances are
If your op needs to do some transformation on the data, chances are
...
@@ -161,7 +165,39 @@ An example calling the above kernel would be::
...
@@ -161,7 +165,39 @@ An example calling the above kernel would be::
// ...
// ...
Wrapping exisiting libraries
A Complete Example
==================
This is a complete example using both approches for a implementation
of the Eye operation.
GpuKernelBase
-------------
Python File
~~~~~~~~~~~
.. literalinclude:: ../../theano/gpuarray/basic_ops.py
:language: python
:pyobject: GpuEye
CGpuKernelBase
--------------
Python File
~~~~~~~~~~~
.. literalinclude:: ../../theano/gpuarray/tests/test_cgpukernelbase.py
:language: python
:pyobject: GpuEye
``tstgpueye.c``
~~~~~~~~~~~~~~~
.. literalinclude:: ../../theano/gpuarray/tests/tstgpueye.c
:language: C
Wrapping Exisiting Libraries
============================
============================
PyCUDA
PyCUDA
...
...
theano/gpuarray/tests/test_cgpukernelbase.py
浏览文件 @
74138d60
...
@@ -3,7 +3,7 @@ import numpy
...
@@ -3,7 +3,7 @@ import numpy
from
six.moves
import
xrange
from
six.moves
import
xrange
import
theano
import
theano
from
theano
import
tensor
,
config
,
Apply
from
theano
import
tensor
,
config
,
Apply
,
Op
from
theano.gradient
import
grad_undefined
from
theano.gradient
import
grad_undefined
from
.config
import
mode_with_gpu
,
test_ctx_name
from
.config
import
mode_with_gpu
,
test_ctx_name
...
@@ -15,7 +15,7 @@ from ..type import GpuArrayType, get_context
...
@@ -15,7 +15,7 @@ from ..type import GpuArrayType, get_context
from
pygpu.gpuarray
import
dtype_to_typecode
from
pygpu.gpuarray
import
dtype_to_typecode
class
TSTGpuEye
(
CGpuKernelBase
):
class
GpuEye
(
CGpuKernelBase
,
Op
):
"""
"""
Eye for GPU.
Eye for GPU.
...
@@ -61,7 +61,7 @@ class TSTGpuEye(CGpuKernelBase):
...
@@ -61,7 +61,7 @@ class TSTGpuEye(CGpuKernelBase):
def
test_cgpukernelbase
():
def
test_cgpukernelbase
():
op
=
TST
GpuEye
(
dtype
=
'int32'
,
context_name
=
test_ctx_name
)
op
=
GpuEye
(
dtype
=
'int32'
,
context_name
=
test_ctx_name
)
f
=
theano
.
function
([],
op
(
4
,
5
),
mode
=
mode_with_gpu
)
f
=
theano
.
function
([],
op
(
4
,
5
),
mode
=
mode_with_gpu
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论