Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
59553e0a
提交
59553e0a
authored
2月 23, 2017
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a blurb about how to deal with float16.
上级
0faeaab5
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
5 行删除
+48
-5
extending_theano_gpu.txt
doc/extending/extending_theano_gpu.txt
+28
-5
fp16_help.py
theano/gpuarray/fp16_help.py
+20
-0
没有找到文件。
doc/extending/extending_theano_gpu.txt
浏览文件 @
59553e0a
...
@@ -156,25 +156,48 @@ in most cases in your :meth:`c_code` method. This is done by using
...
@@ -156,25 +156,48 @@ in most cases in your :meth:`c_code` method. This is done by using
the provided wrapper function. An example calling the above kernel
the provided wrapper function. An example calling the above kernel
would be::
would be::
size_t ls, gs;
size_t dims[2];
size_t dims[2];
size_t n = 256;
// ...
// ...
ls = 1;
err = k_scall(1, &n, 0, input->ga.data, dims[0], dims[1]);
gs = 256;
err = k_call(1, &gs, &ls, 0, input->ga.data, dims[0], dims[1]);
// ...
If you want explicit control over the scheduling, you can use the
`_call` wrapper instead which works like this::
size_t ls, gs;
// ...
// ...
gs = 1;
ls = 256;
err = k_call(1, &gs, &ls, 0, input->ga.data, dims[0], dims[1]);
The name of the wrapper function depends on the name you passed to
The name of the wrapper function depends on the name you passed to
``Kernel()`` when you declared it (or the name in your `#kernel`
``Kernel()`` when you declared it (or the name in your `#kernel`
statement). It defaults to `name + '_call'`.
statement). It defaults to `name + '_call'
or '_scall'
`.
For other operations in the C code you should refer to the
For other operations in the C code you should refer to the
`libgpuarray documentation
`libgpuarray documentation
<http://deeplearning.net/software/libgpuarray/>`_.
<http://deeplearning.net/software/libgpuarray/>`_.
Dealing with float16
====================
To support limited-precision storage in a kernel you have to be
careful to load values properly, declare working memory in float32 and
write results properly. To help with that some functions have been
declared in `theano.gpuarray.fp16_help`.
To load the inputs you should wrap the read with the function returned
by :function:`load_w`. Similarly writes should be wrapped in the
function returned by :function:`write_w`. Finally working data should
have the type returned by :function:`work_dtype`.
A Complete Example
A Complete Example
==================
==================
...
...
theano/gpuarray/fp16_help.py
浏览文件 @
59553e0a
...
@@ -2,6 +2,10 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,6 +2,10 @@ from __future__ import absolute_import, print_function, division
def
work_dtype
(
dtype
):
def
work_dtype
(
dtype
):
"""
Return the data type for working memory.
"""
if
dtype
==
'float16'
:
if
dtype
==
'float16'
:
return
'float32'
return
'float32'
else
:
else
:
...
@@ -9,6 +13,14 @@ def work_dtype(dtype):
...
@@ -9,6 +13,14 @@ def work_dtype(dtype):
def
load_w
(
dtype
):
def
load_w
(
dtype
):
"""
Return the function name to load data.
This should be used like this::
code = '
%(load_f)
s(ival)'
%
(load_w(input_type),)
"""
if
dtype
==
'float16'
:
if
dtype
==
'float16'
:
return
'__half2float'
return
'__half2float'
else
:
else
:
...
@@ -16,6 +28,14 @@ def load_w(dtype):
...
@@ -16,6 +28,14 @@ def load_w(dtype):
def
write_w
(
dtype
):
def
write_w
(
dtype
):
"""
Return the function name to write data.
This should be used like this::
code = 'res =
%(write_f)
s(oval)'
%
(write_w(output_type),)
"""
if
dtype
==
'float16'
:
if
dtype
==
'float16'
:
return
'__float2half_rn'
return
'__float2half_rn'
else
:
else
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论