Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c2c34032
提交
c2c34032
authored
3月 26, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
97fff534
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
37 行增加
和
20 行删除
+37
-20
kernel_codegen.py
theano/sandbox/cuda/kernel_codegen.py
+37
-20
没有找到文件。
theano/sandbox/cuda/kernel_codegen.py
浏览文件 @
c2c34032
""" Helper routines for generating gpu kernels for nvcc.
""" Helper routines for generating gpu kernels for nvcc.
"""
"""
def
nvcc_kernel
(
name
,
params
,
body
):
def
nvcc_kernel
(
name
,
params
,
body
):
"""Return the c code of a kernel function.
"""Return the c code of a kernel function.
:param params: the parameters to the function as one or more strings
:param params: the parameters to the function as one or more strings
:param body: the [nested] list of statements for the body of the function. These will be
:param body: the [nested] list of statements for the body of the
separated by ';' characters.
function. These will be separated by ';' characters.
"""
"""
paramstr
=
', '
.
join
(
params
)
paramstr
=
', '
.
join
(
params
)
def
flatbody
():
def
flatbody
():
for
b
in
body
:
for
b
in
body
:
if
isinstance
(
b
,
(
list
,
tuple
)):
if
isinstance
(
b
,
(
list
,
tuple
)):
...
@@ -21,12 +25,14 @@ def nvcc_kernel(name, params, body):
...
@@ -21,12 +25,14 @@ def nvcc_kernel(name, params, body):
{
{
%(bodystr)
s;
%(bodystr)
s;
}
}
"""
%
locals
()
"""
%
locals
()
def
code_version
(
version
):
def
code_version
(
version
):
"""decorator to support version-based cache mechanism"""
"""decorator to support version-based cache mechanism"""
if
not
isinstance
(
version
,
tuple
):
if
not
isinstance
(
version
,
tuple
):
raise
TypeError
(
'version must be tuple'
,
version
)
raise
TypeError
(
'version must be tuple'
,
version
)
def
deco
(
f
):
def
deco
(
f
):
f
.
code_version
=
version
f
.
code_version
=
version
return
f
return
f
...
@@ -34,31 +40,33 @@ def code_version(version):
...
@@ -34,31 +40,33 @@ def code_version(version):
UNVERSIONED
=
()
UNVERSIONED
=
()
@code_version
((
1
,))
@code_version
((
1
,))
def
inline_reduce
(
N
,
buf
,
pos
,
count
,
manner_fn
):
def
inline_reduce
(
N
,
buf
,
pos
,
count
,
manner_fn
):
"""
"""Return C++ code for a function that reduces a contiguous buffer.
Return C++ code for a function that reduces a contiguous buffer.
:param N: length of the buffer
:param N: length of the buffer
:param buf: buffer pointer
:param buf: buffer pointer
:param pos: index of executing thread
:param pos: index of executing thread
:param count: number of executing threads
:param count: number of executing threads
:param manner_fn: a function that accepts strings of arguments a and b, and returns c code
for their reduction. (Example: return "
%(a)
s +
%(b)
s" for a sum reduction).
:param manner_fn: a function that accepts strings of arguments a
and b, and returns c code for their reduction. (Example:
return "
%(a)
s +
%(b)
s" for a sum reduction).
:postcondition:
:postcondition:
This function leaves the answer in position 0 of the buffer. The
rest of the buffer is
This function leaves the answer in position 0 of the buffer. The
trashed by this function.
rest of the buffer is
trashed by this function.
:note: buf should be in gpu shared memory, we access it many times.
:note: buf should be in gpu shared memory, we access it many times.
"""
"""
loop_line
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[i]"
%
(
buf
))
loop_line
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[i]"
%
(
buf
))
r_16
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+16]"
%
(
buf
,
pos
))
r_16
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+16]"
%
(
buf
,
pos
))
r_8
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+8]"
%
(
buf
,
pos
))
r_8
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+8]"
%
(
buf
,
pos
))
r_4
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+4]"
%
(
buf
,
pos
))
r_4
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+4]"
%
(
buf
,
pos
))
r_2
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+2]"
%
(
buf
,
pos
))
r_2
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+2]"
%
(
buf
,
pos
))
r_1
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+1]"
%
(
buf
,
pos
))
r_1
=
manner_fn
(
"
%
s[
%
s]"
%
(
buf
,
pos
),
"
%
s[
%
s+1]"
%
(
buf
,
pos
))
return
"""
return
"""
{
{
...
@@ -88,24 +96,33 @@ def inline_reduce(N, buf, pos, count, manner_fn):
...
@@ -88,24 +96,33 @@ def inline_reduce(N, buf, pos, count, manner_fn):
}
}
"""
%
locals
()
"""
%
locals
()
@code_version
(
inline_reduce
.
code_version
)
@code_version
(
inline_reduce
.
code_version
)
def
inline_reduce_max
(
N
,
buf
,
pos
,
count
):
def
inline_reduce_max
(
N
,
buf
,
pos
,
count
):
return
inline_reduce
(
N
,
buf
,
pos
,
count
,
lambda
a
,
b
:
"max(
%
s,
%
s)"
%
(
a
,
b
))
return
inline_reduce
(
N
,
buf
,
pos
,
count
,
lambda
a
,
b
:
"max(
%
s,
%
s)"
%
(
a
,
b
))
@code_version
(
inline_reduce
.
code_version
)
@code_version
(
inline_reduce
.
code_version
)
def
inline_reduce_sum
(
N
,
buf
,
pos
,
count
):
def
inline_reduce_sum
(
N
,
buf
,
pos
,
count
):
return
inline_reduce
(
N
,
buf
,
pos
,
count
,
lambda
a
,
b
:
"
%
s +
%
s"
%
(
a
,
b
))
return
inline_reduce
(
N
,
buf
,
pos
,
count
,
lambda
a
,
b
:
"
%
s +
%
s"
%
(
a
,
b
))
@code_version
(
inline_reduce
.
code_version
)
@code_version
(
inline_reduce
.
code_version
)
def
inline_reduce_min
(
N
,
buf
,
pos
,
count
):
def
inline_reduce_min
(
N
,
buf
,
pos
,
count
):
return
inline_reduce
(
N
,
buf
,
pos
,
count
,
lambda
a
,
b
:
"min(
%
s,
%
s)"
%
(
a
,
b
))
return
inline_reduce
(
N
,
buf
,
pos
,
count
,
lambda
a
,
b
:
"min(
%
s,
%
s)"
%
(
a
,
b
))
@code_version
(
inline_reduce
.
code_version
)
@code_version
(
inline_reduce
.
code_version
)
def
inline_reduce_prod
(
N
,
buf
,
pos
,
count
):
def
inline_reduce_prod
(
N
,
buf
,
pos
,
count
):
return
inline_reduce
(
N
,
buf
,
pos
,
count
,
lambda
a
,
b
:
"
%
s *
%
s"
%
(
a
,
b
))
return
inline_reduce
(
N
,
buf
,
pos
,
count
,
lambda
a
,
b
:
"
%
s *
%
s"
%
(
a
,
b
))
@code_version
((
2
,)
+
inline_reduce_max
.
code_version
+
inline_reduce_sum
.
code_version
)
@code_version
((
2
,)
+
inline_reduce_max
.
code_version
+
inline_reduce_sum
.
code_version
)
def
inline_softmax
(
N
,
buf
,
buf2
,
threadPos
,
threadCount
):
def
inline_softmax
(
N
,
buf
,
buf2
,
threadPos
,
threadCount
):
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论