Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b33b4462
提交
b33b4462
authored
6月 03, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix mistakes and typos and add a kernel call example.
上级
6c42f5e3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
41 行增加
和
22 行删除
+41
-22
extending_theano_gpu.txt
doc/extending/extending_theano_gpu.txt
+41
-22
没有找到文件。
doc/extending/extending_theano_gpu.txt
浏览文件 @
b33b4462
...
...
@@ -38,13 +38,13 @@ written. An example usage is below::
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
should not pass it to `infer_context_name`.
should not pass it to
:func:
`infer_context_name`.
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
not enough to know you want the value to be on the GPU, you also want
to know which GPU to put it on. In almost all cases, you can pass in
the return value of `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
the output). You can use the context of one of your inputs to know
...
...
@@ -90,35 +90,36 @@ COp functionality).
For plain 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
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):
code = """
KERNEL void k(GLOBAL_MEM ga_float
*a, ga_size n, ga_size m) {
ga_size nb = n < m ? n : m;
for (ga_size i = LID_0; i < nb; i += LDIM_0) {
a[i*m + i] = 1;
}
}"""
KERNEL void k(GLOBAL_MEM ga_double
*a, ga_size n, ga_size m) {
ga_size nb = n < m ? n : m;
for (ga_size i = LID_0; i < nb; i += LDIM_0) {
a[i*m + i] = 1;
}
}"""
return [Kernel(
code=code, name="k",
params=[gpuarray.GpuArray, gpuarray.SIZE, gpuarray.SIZE],
flags=Kernel.get_flags(
self.dtype
))]
flags=Kernel.get_flags(
'float64'
))]
If you want to use COp, then you should use `
CGpuKernelBase` instead.
It add a new section to the parsed files whose tag is `kernels`.
Inside that section you can define some kernels with `#kernel
name:params:flags
`.
If you want to use COp, then you should use `
`CGpuKernelBase``
instead. It adds a new section to the parsed files whose tag is
``kernels``. Inside that section you can define some kernels with
``#kernel name:params:flags`
`.
Here `name` is the name of the kernel function in the following code,
`params` is a comma-separeted list of C typecode names and `flags` is
a `|`-separeted list of C kernel flag values (can be empty). The same kernel definition as above would look like this with `CGpuKernelBase`:
Here ``name`` is the name of the kernel function in the following code,
``params`` is a comma-separeted list of C typecode names and ``flags`` is
a ``|``-separeted list of C kernel flag values (can be empty). The same
kernel definition as above would look like this with ``CGpuKernelBase``::
#section kernels
#kernel k : GA_BUFFER, GA_SIZE, GA_SIZE : GA_USE_CLUDA
#kernel k : GA_BUFFER, GA_SIZE, GA_SIZE : GA_USE_CLUDA
|GA_USE_DOUBLE
KERNEL void k(GLOBAL_MEM ga_
float
*a, ga_size n, ga_size m) {
KERNEL void k(GLOBAL_MEM ga_
double
*a, ga_size n, ga_size m) {
ga_size nb = n < m ? n : m;
for (ga_size i = LID_0; i < nb; i += LDIM_0) {
a[i*m + i] = 1;
...
...
@@ -128,7 +129,25 @@ a `|`-separeted list of C kernel flag values (can be empty). The same kernel de
The second method is to handle the kernel compilation and cache on
your own. This is not recommended because there are lots of details
to pay attention to that can cripple your performance if not done
right, which GpuKernelBase handles for you.
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
libgpuarray.
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.
This is done using the ``GpuKernel_call()`` method in your C code.
An example calling the above kernel would be::
size_t ls, gs;
size_t dims[2];
void *args[3];
// ...
args[0] = input->ga.data;
args[1] = &dims[0];
args[2] = &dims[1];
ls = 1;
gs = 256;
err = GpuKernel_call(&%(kname)s, 1, &ls, &gs, 0, args);
// ...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论