Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0f1d6881
提交
0f1d6881
authored
10月 16, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
aaf09989
31b44f44
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
39 行增加
和
8 行删除
+39
-8
__init__.py
__init__.py
+14
-0
elemwise.py
elemwise.py
+3
-0
nvcc_compiler.py
nvcc_compiler.py
+5
-3
opt.py
opt.py
+1
-1
type.py
type.py
+16
-4
没有找到文件。
__init__.py
浏览文件 @
0f1d6881
...
@@ -7,14 +7,28 @@ from .var import (CudaNdarrayVariable,
...
@@ -7,14 +7,28 @@ from .var import (CudaNdarrayVariable,
import
basic_ops
import
basic_ops
import
opt
import
opt
import
cuda_ndarray
import
theano.compile.sandbox
import
theano.compile.sandbox
import
logging
,
os
def
use
():
handle_shared_float32
(
True
)
def
handle_shared_float32
(
tf
):
def
handle_shared_float32
(
tf
):
"""Set the CudaNdarrayType as the default handler for shared float32 arrays
"""Set the CudaNdarrayType as the default handler for shared float32 arrays
Use use(tf) instead as this is a bad name.
"""
"""
if
tf
:
if
tf
:
try
:
v
=
os
.
getenv
(
"THEANO_GPU"
,
0
)
cuda_ndarray
.
gpu_init
(
int
(
v
))
theano
.
compile
.
sandbox
.
shared_constructor
(
shared_constructor
)
theano
.
compile
.
sandbox
.
shared_constructor
(
shared_constructor
)
except
RuntimeError
,
e
:
logging
.
getLogger
(
'theano_cuda_ndarray'
)
.
warning
(
"WARNING: Won't use the GPU as the initialisation failed."
+
str
(
e
))
else
:
else
:
raise
NotImplementedError
(
'removing our handler'
)
raise
NotImplementedError
(
'removing our handler'
)
elemwise.py
浏览文件 @
0f1d6881
...
@@ -880,6 +880,8 @@ class NaiveAlgo(object):
...
@@ -880,6 +880,8 @@ class NaiveAlgo(object):
print
>>
sio
,
"""
print
>>
sio
,
"""
int dims[
%(nd)
s] = {
%(initial_dims)
s};
int dims[
%(nd)
s] = {
%(initial_dims)
s};
"""
%
locals
()
"""
%
locals
()
#check that all inputs have valid dimensions
for
iname
in
inputs
:
for
iname
in
inputs
:
print
>>
sio
,
"""
print
>>
sio
,
"""
//std::cerr << "C_CODE
%(opname)
s checking input
%(iname)
s
\\
n";
//std::cerr << "C_CODE
%(opname)
s checking input
%(iname)
s
\\
n";
...
@@ -904,6 +906,7 @@ class NaiveAlgo(object):
...
@@ -904,6 +906,7 @@ class NaiveAlgo(object):
}
}
"""
%
locals
()
"""
%
locals
()
#check that all outputs have valid dimensions
for
oname
in
outputs
:
for
oname
in
outputs
:
print
>>
sio
,
"""
print
>>
sio
,
"""
for (int i = 0; (i<
%(nd)
s) && (cnda_
%(oname)
s); ++i) {
for (int i = 0; (i<
%(nd)
s) && (cnda_
%(oname)
s); ++i) {
...
...
nvcc_compiler.py
浏览文件 @
0f1d6881
...
@@ -34,10 +34,12 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[
...
@@ -34,10 +34,12 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[
preargs
=
[]
if
preargs
is
None
else
list
(
preargs
)
preargs
=
[]
if
preargs
is
None
else
list
(
preargs
)
preargs
.
append
(
'-fPIC'
)
preargs
.
append
(
'-fPIC'
)
no_opt
=
False
no_opt
=
False
cuda_root
=
os
.
getenv
(
'CUDA_ROOT'
)
include_dirs
=
std_include_dirs
()
+
include_dirs
include_dirs
=
std_include_dirs
()
+
include_dirs
libs
=
std_libs
()
+
[
'cudart'
]
+
libs
libs
=
std_libs
()
+
[
'cudart'
]
+
libs
lib_dirs
=
std_lib_dirs
()
+
[
os
.
path
.
join
(
os
.
getenv
(
'CUDA_ROOT'
),
'lib'
)]
+
lib_dirs
lib_dirs
=
std_lib_dirs
()
+
lib_dirs
if
cuda_root
:
lib_dirs
.
append
(
os
.
path
.
join
(
cuda_root
,
'lib'
))
cppfilename
=
os
.
path
.
join
(
location
,
'mod.cu'
)
cppfilename
=
os
.
path
.
join
(
location
,
'mod.cu'
)
cppfile
=
file
(
cppfilename
,
'w'
)
cppfile
=
file
(
cppfilename
,
'w'
)
...
@@ -83,7 +85,7 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[
...
@@ -83,7 +85,7 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[
print
'==============================='
print
'==============================='
for
i
,
l
in
enumerate
(
src_code
.
split
(
'
\n
'
)):
for
i
,
l
in
enumerate
(
src_code
.
split
(
'
\n
'
)):
print
i
+
1
,
l
print
i
+
1
,
l
raise
Exception
(
'nvcc return status'
,
p
.
returncode
)
raise
Exception
(
'nvcc return status'
,
p
.
returncode
,
'for file'
,
cppfilename
)
#touch the __init__ file
#touch the __init__ file
file
(
os
.
path
.
join
(
location
,
"__init__.py"
),
'w'
)
.
close
()
file
(
os
.
path
.
join
(
location
,
"__init__.py"
),
'w'
)
.
close
()
...
...
opt.py
浏览文件 @
0f1d6881
...
@@ -175,7 +175,7 @@ def local_gpu_flatten(node):
...
@@ -175,7 +175,7 @@ def local_gpu_flatten(node):
host_input
=
node
.
inputs
[
0
]
host_input
=
node
.
inputs
[
0
]
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
tensor
.
Flatten
):
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
tensor
.
Flatten
):
outdim
=
host_input
.
owner
.
op
.
outdim
outdim
=
host_input
.
owner
.
op
.
outdim
return
[
GpuFlatten
(
outdim
)(
gpu_from_host
(
host_input
.
inputs
[
0
]))]
return
[
GpuFlatten
(
outdim
)(
gpu_from_host
(
host_input
.
owner
.
inputs
[
0
]))]
if
isinstance
(
node
.
op
,
tensor
.
Flatten
):
if
isinstance
(
node
.
op
,
tensor
.
Flatten
):
x
,
=
node
.
inputs
x
,
=
node
.
inputs
outdim
=
node
.
op
.
outdim
outdim
=
node
.
op
.
outdim
...
...
type.py
浏览文件 @
0f1d6881
...
@@ -52,8 +52,14 @@ class CudaNdarrayType(Type):
...
@@ -52,8 +52,14 @@ class CudaNdarrayType(Type):
def
filter
(
self
,
data
,
strict
=
False
):
def
filter
(
self
,
data
,
strict
=
False
):
return
type_support_filter
(
data
,
self
.
broadcastable
,
strict
)
return
type_support_filter
(
data
,
self
.
broadcastable
,
strict
)
@staticmethod
def
values_eq
(
a
,
b
):
#TODO: make the comparaison without transfert.
return
tensor
.
TensorType
.
values_eq
(
numpy
.
asarray
(
a
),
numpy
.
asarray
(
b
))
@staticmethod
@staticmethod
def
values_eq_approx
(
a
,
b
):
def
values_eq_approx
(
a
,
b
):
#TODO: make the comparaison without transfert.
return
tensor
.
TensorType
.
values_eq_approx
(
numpy
.
asarray
(
a
),
numpy
.
asarray
(
b
))
return
tensor
.
TensorType
.
values_eq_approx
(
numpy
.
asarray
(
a
),
numpy
.
asarray
(
b
))
def
dtype_specs
(
self
):
def
dtype_specs
(
self
):
...
@@ -229,12 +235,18 @@ class CudaNdarrayType(Type):
...
@@ -229,12 +235,18 @@ class CudaNdarrayType(Type):
def
c_header_dirs
(
self
):
def
c_header_dirs
(
self
):
"""Override `CLinkerOp.c_headers` """
"""Override `CLinkerOp.c_headers` """
return
[
os
.
path
.
dirname
(
cuda_ndarray
.
__file__
),
ret
=
[
os
.
path
.
dirname
(
cuda_ndarray
.
__file__
)]
os
.
path
.
join
(
os
.
getenv
(
"CUDA_ROOT"
),
'include'
)]
cuda_root
=
os
.
getenv
(
"CUDA_ROOT"
)
if
cuda_root
:
ret
.
append
(
os
.
path
.
join
(
cuda_root
,
'include'
))
return
ret
def
c_lib_dirs
(
self
):
def
c_lib_dirs
(
self
):
return
[
os
.
path
.
dirname
(
cuda_ndarray
.
__file__
),
ret
=
[
os
.
path
.
dirname
(
cuda_ndarray
.
__file__
)]
os
.
path
.
join
(
os
.
getenv
(
"CUDA_ROOT"
),
'lib'
)]
cuda_root
=
os
.
getenv
(
"CUDA_ROOT"
)
if
cuda_root
:
ret
.
append
(
os
.
path
.
join
(
cuda_root
,
'lib'
))
return
ret
def
c_libraries
(
self
):
def
c_libraries
(
self
):
return
[
'cuda_ndarray'
,
'cudart'
]
return
[
'cuda_ndarray'
,
'cudart'
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论