Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
65ab2e1b
提交
65ab2e1b
authored
4月 03, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add the missing class PycudaElemwiseSourceModuleMakeThunkOp used by some tests.
上级
b191ea8c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
93 行增加
和
0 行删除
+93
-0
pycuda_example.py
theano/misc/pycuda_example.py
+93
-0
没有找到文件。
theano/misc/pycuda_example.py
浏览文件 @
65ab2e1b
...
@@ -175,6 +175,99 @@ class PycudaElemwiseSourceModuleOp(GpuOp):
...
@@ -175,6 +175,99 @@ class PycudaElemwiseSourceModuleOp(GpuOp):
numpy
.
intc
(
inputs
[
1
]
.
size
),
block
=
block
,
grid
=
grid
)
numpy
.
intc
(
inputs
[
1
]
.
size
),
block
=
block
,
grid
=
grid
)
class
PycudaElemwiseSourceModuleMakeThunkOp
(
Op
):
nin
=
property
(
lambda
self
:
self
.
scalar_op
.
nin
)
nout
=
property
(
lambda
self
:
self
.
scalar_op
.
nout
)
def
__init__
(
self
,
scalar_op
,
inplace_pattern
=
{},
name
=
None
):
self
.
name
=
name
self
.
scalar_op
=
scalar_op
self
.
inplace_pattern
=
None
def
__str__
(
self
):
if
self
.
name
is
None
:
if
self
.
inplace_pattern
:
items
=
self
.
inplace_pattern
.
items
()
items
.
sort
()
return
self
.
__class__
.
__name__
+
"{
%
s}
%
s"
%
(
self
.
scalar_op
,
str
(
items
))
else
:
return
self
.
__class__
.
__name__
+
"{
%
s}"
%
(
self
.
scalar_op
)
else
:
return
self
.
name
def
make_node
(
self
,
*
inputs
):
assert
self
.
nout
==
1
assert
len
(
inputs
)
==
2
# TODO remove
_inputs
=
[
gpu_contiguous
(
as_cuda_ndarray_variable
(
i
))
for
i
in
inputs
]
if
self
.
nin
>
0
and
len
(
_inputs
)
!=
self
.
nin
:
raise
TypeError
(
'Wrong argument count'
,
(
self
.
nin
,
len
(
_inputs
)))
for
i
in
_inputs
[
1
:]:
if
i
.
type
.
ndim
!=
inputs
[
0
]
.
type
.
ndim
:
raise
TypeError
(
'different ranks among inputs'
)
if
any
([
any
(
i
.
type
.
broadcastable
)
for
i
in
inputs
]):
raise
Exception
(
"pycuda don't support broadcasted dimensions"
)
otype
=
CudaNdarrayType
(
broadcastable
=
[
False
]
*
_inputs
[
0
]
.
type
.
ndim
)
out_node
=
Apply
(
self
,
_inputs
,
[
otype
()
for
o
in
xrange
(
self
.
nout
)])
return
out_node
def
make_thunk
(
self
,
node
,
storage_map
,
_
,
_2
):
#TODO support broadcast!
#TODO assert all input have the same shape
fct_name
=
"pycuda_elemwise_
%
s"
%
str
(
self
.
scalar_op
)
in_name
=
[
"i"
+
str
(
id
)
for
id
in
range
(
len
(
node
.
inputs
))]
out_name
=
[
"o"
+
str
(
id
)
for
id
in
range
(
self
.
nout
)]
c_code
=
self
.
scalar_op
.
c_code
(
node
,
"some_name"
,
tuple
([
n
+
"[i]"
for
n
in
in_name
]),
tuple
(
n
+
"[i]"
for
n
in
out_name
),
{})
c_code_param
=
", "
.
join
([
var
.
type
.
dtype_specs
()[
1
]
+
" *"
+
name
for
var
,
name
in
zip
(
node
.
inputs
,
in_name
)
+
zip
(
node
.
outputs
,
out_name
)]
+
[
"int size"
])
mod
=
SourceModule
(
"""
#include<Python.h>
#include <numpy/arrayobject.h>
__global__ void
%
s(
%
s)
{
int i = (blockIdx.x+blockIdx.y*gridDim.x)*(blockDim.x*blockDim.y);
i += threadIdx.x + threadIdx.y*blockDim.x;
if(i<size){
%
s
}
}
"""
%
(
fct_name
,
c_code_param
,
c_code
))
pycuda_fct
=
mod
.
get_function
(
fct_name
)
inputs
=
[
storage_map
[
v
]
for
v
in
node
.
inputs
]
outputs
=
[
storage_map
[
v
]
for
v
in
node
.
outputs
]
def
thunk
():
z
=
outputs
[
0
]
if
z
[
0
]
is
None
or
z
[
0
]
.
shape
!=
inputs
[
0
][
0
]
.
shape
:
z
[
0
]
=
theano
.
sandbox
.
cuda
.
CudaNdarray
.
zeros
(
inputs
[
0
][
0
]
.
shape
)
if
inputs
[
0
][
0
]
.
shape
!=
inputs
[
1
][
0
]
.
shape
:
raise
TypeError
(
"PycudaElemwiseSourceModuleMakeThunkOp:"
" inputs don't have the same shape!"
)
if
inputs
[
0
][
0
]
.
size
>
512
:
grid
=
(
int
(
numpy
.
ceil
(
inputs
[
0
][
0
]
.
size
/
512.
)),
1
)
block
=
(
512
,
1
,
1
)
else
:
grid
=
(
1
,
1
)
block
=
(
inputs
[
0
][
0
]
.
shape
[
0
],
inputs
[
0
][
0
]
.
shape
[
1
],
1
)
out
=
pycuda_fct
(
inputs
[
0
][
0
],
inputs
[
1
][
0
],
z
[
0
],
numpy
.
intc
(
inputs
[
1
][
0
]
.
size
),
block
=
block
,
grid
=
grid
)
thunk
.
inputs
=
inputs
thunk
.
outputs
=
outputs
thunk
.
lazy
=
False
return
thunk
class
PycudaElemwiseKernelOp
(
GpuOp
):
class
PycudaElemwiseKernelOp
(
GpuOp
):
nin
=
property
(
lambda
self
:
self
.
scalar_op
.
nin
)
nin
=
property
(
lambda
self
:
self
.
scalar_op
.
nin
)
nout
=
property
(
lambda
self
:
self
.
scalar_op
.
nout
)
nout
=
property
(
lambda
self
:
self
.
scalar_op
.
nout
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论