Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9dde5536
提交
9dde5536
authored
6月 22, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix nitpicking (not my words).
上级
74138d60
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
22 行删除
+30
-22
extending_theano_gpu.txt
doc/extending/extending_theano_gpu.txt
+28
-22
test_cgpukernelbase.py
theano/gpuarray/tests/test_cgpukernelbase.py
+2
-0
没有找到文件。
doc/extending/extending_theano_gpu.txt
浏览文件 @
9dde5536
...
@@ -12,12 +12,12 @@ Extending Theano with a GPU Op
...
@@ -12,12 +12,12 @@ Extending Theano with a GPU Op
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
:ref:`extending_theano` and :ref:`extending_theano_c` section before
:ref:`extending_theano` and :ref:`extending_theano_c` section
s
before
continuing on.
continuing on.
Writing a new GPU op can be done in
p
ython for some simple tasks, but
Writing a new GPU op can be done in
P
ython 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
p
ython function call.
overhead of a
P
ython function call.
Dealing With the Context
Dealing With the Context
========================
========================
...
@@ -25,7 +25,7 @@ Dealing With the Context
...
@@ -25,7 +25,7 @@ Dealing With the Context
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
context (a.k.a. device) to execute. Most of the time you can infer
context (a.k.a. device) to execute. Most of the time you can infer
the context to run on from your inputs. There is a way for the user
the context to run on from your inputs. There is a way for the user
to transfer things between contexts and to tag certain var
ai
bles for
to transfer things between contexts and to tag certain var
ia
bles for
transfer. It might also be the case that your inputs are not all from
transfer. It might also be the case that your inputs are not all from
the same context and you would have to choose which one to run on.
the same context and you would have to choose which one to run on.
...
@@ -42,7 +42,8 @@ written. An example usage is below::
...
@@ -42,7 +42,8 @@ written. An example usage is below::
In this example the Op takes three inputs, all on the GPU. In case
In this example the Op takes three inputs, all on the GPU. In case
one or more of your inputs is not supposed to be on the GPU, you
one or more of your inputs is not supposed to be on the GPU, you
should not pass it to :func:`infer_context_name`.
should not pass it to :func:`infer_context_name` or call
:func:`as_gpuarray_variable` on it.
Also note that :func:`theano.gpuarray.basic_ops.as_gpuarray_variable`
Also note that :func:`theano.gpuarray.basic_ops.as_gpuarray_variable`
takes ``context_name`` as a mandatory parameter. This is because it's
takes ``context_name`` as a mandatory parameter. This is because it's
...
@@ -51,7 +52,7 @@ to know which GPU to put it on. In almost all cases, you can pass in
...
@@ -51,7 +52,7 @@ to know which GPU to put it on. In almost all cases, you can pass in
the return value of :func:`infer_context_name` there.
the return value of :func:`infer_context_name` there.
If you also need the context during runtime (for example to allocate
If you also need the context during runtime (for example to allocate
the output)
. Y
ou can use the context of one of your inputs to know
the output)
, y
ou can use the context of one of your inputs to know
which one to use. Here is another example::
which one to use. Here is another example::
def perform(self, node, inputs, output_storage):
def perform(self, node, inputs, output_storage):
...
@@ -62,15 +63,15 @@ which one to use. Here is another example::
...
@@ -62,15 +63,15 @@ which one to use. Here is another example::
Finally if you require the context before perform, such as during
Finally if you require the context before perform, such as during
make_thunk() to initialize kernels and such, you can access the
make_thunk() to initialize kernels and such, you can access the
context of your inputs through the type
i
f the variables::
context of your inputs through the type
o
f the variables::
def make_thunk(self, node, storage_map, compute_map, no_recycling):
def make_thunk(self, node, storage_map, compute_map, no_recycling):
ctx = node.inputs[0].type.context
ctx = node.inputs[0].type.context
Note that
GpuArrayType objects also have a `context_name` attribute
Note that
``GpuArrayType`` objects also have a ``context_name``
which is the symbolic equivalent of `context`. It can't be used for
attribute which is the symbolic equivalent of ``context``. It can't
calls to pygpu or libgpuarray, but it should be used for theano
be used for calls to pygpu or libgpuarray, but it should be used for
operations and variables.
theano
operations and variables.
The last place where you might need the context is in the C
The last place where you might need the context is in the C
initialization code. For that you will have to use the :ref:`params
initialization code. For that you will have to use the :ref:`params
...
@@ -91,13 +92,17 @@ Defining New Kernels
...
@@ -91,13 +92,17 @@ Defining New Kernels
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
that you will need to write a new kernel. The best way to do this is
that you will need to write a new kernel. The best way to do this is
to leverage GpuKernelBase (or CGpuKernelBase if you want to use the
to leverage :class:`GpuKernelBase
COp functionality).
<theano.gpuarray.basic_ops.GpuKernelBase>` (or :class:`CGpuKernelBase
<theano.gpuarray.basic_ops.CGpuKernelBase>` if you want to use the
For plain GpuKernelBase, you have to define a method called
:class:`COp <theano.gof.op.COp>` functionality).
gpu_kernels which returns a list of :class:`Kernel
For plain :class:`GpuKernelBase
<theano.gpuarray.basic_ops.GpuKernelBase>`, you have to define a
method called ``gpu_kernels`` which returns a list of :class:`Kernel
<theano.gpuarray.basic_ops.Kernel>` objects. You can define as many
<theano.gpuarray.basic_ops.Kernel>` objects. You can define as many
kernels as you want for a single op. An example would look like this::
kernels as you want for a single op. An example would look like
this::
def gpu_kernels(self, node, name):
def gpu_kernels(self, node, name):
code = """
code = """
...
@@ -123,7 +128,7 @@ There are three exceptions for ``size_t`` which should be noted as
...
@@ -123,7 +128,7 @@ There are three exceptions for ``size_t`` which should be noted as
``size``, ``ssize_t`` which should be noted as ``ssize`` and a pointer
``size``, ``ssize_t`` which should be noted as ``ssize`` and a pointer
which should be noted as ``*``.
which should be noted as ``*``.
``flags`` is a ``|``-separ
e
ted list of C kernel flag values (can be
``flags`` is a ``|``-separ
a
ted list of C kernel flag values (can be
empty). The same kernel definition as above would look like this with
empty). The same kernel definition as above would look like this with
``CGpuKernelBase``::
``CGpuKernelBase``::
...
@@ -145,9 +150,10 @@ right, which GpuKernelBase handles for you. But if you really want to
...
@@ -145,9 +150,10 @@ right, which GpuKernelBase handles for you. But if you really want to
go this way, then you can look up the C API for kernels in
go this way, then you can look up the C API for kernels in
libgpuarray.
libgpuarray.
In any case you will need to call your compiled kernel with some data.
In any case you will need to call your compiled kernel with some data,
This is done using the ``GpuKernel_call()`` method in your C code.
in most cases in your :meth:`c_code` method. This is done using the
An example calling the above kernel would be::
``GpuKernel_call()`` function in your C code. An example calling the
above kernel would be::
size_t ls, gs;
size_t ls, gs;
size_t dims[2];
size_t dims[2];
...
@@ -160,7 +166,7 @@ An example calling the above kernel would be::
...
@@ -160,7 +166,7 @@ An example calling the above kernel would be::
args[2] = &dims[1];
args[2] = &dims[1];
ls = 1;
ls = 1;
gs = 256;
gs = 256;
err = GpuKernel_call(&
%(kname)s
, 1, &ls, &gs, 0, args);
err = GpuKernel_call(&
k_obj
, 1, &ls, &gs, 0, args);
// ...
// ...
...
...
theano/gpuarray/tests/test_cgpukernelbase.py
浏览文件 @
9dde5536
...
@@ -15,6 +15,8 @@ from ..type import GpuArrayType, get_context
...
@@ -15,6 +15,8 @@ from ..type import GpuArrayType, get_context
from
pygpu.gpuarray
import
dtype_to_typecode
from
pygpu.gpuarray
import
dtype_to_typecode
# This is an implementation to test that CGpuKernelBase works and also
# to use as an example in the docs. It is not used for user graphs.
class
GpuEye
(
CGpuKernelBase
,
Op
):
class
GpuEye
(
CGpuKernelBase
,
Op
):
"""
"""
Eye for GPU.
Eye for GPU.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论