Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1bc17311
提交
1bc17311
authored
8月 24, 2017
作者:
Frédéric Bastien
提交者:
GitHub
8月 24, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6354 from notoraptor/fix-conv-runtime-algos-with-different-dtypes
Add data type configuration to algorithms hash for cuDNN convolutions caching system
上级
078bdfb1
bcff31c9
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
62 行增加
和
11 行删除
+62
-11
dnn_conv_base.c
theano/gpuarray/c_code/dnn_conv_base.c
+28
-3
dnn_fwd.c
theano/gpuarray/c_code/dnn_fwd.c
+1
-1
dnn_gi.c
theano/gpuarray/c_code/dnn_gi.c
+3
-4
dnn_gw.c
theano/gpuarray/c_code/dnn_gw.c
+2
-3
test_dnn.py
theano/gpuarray/tests/test_dnn.py
+28
-0
没有找到文件。
theano/gpuarray/c_code/dnn_conv_base.c
浏览文件 @
1bc17311
...
@@ -199,7 +199,7 @@ static std::string shape(cudnnFilterDescriptor_t t, cudnnDataType_t* type)
...
@@ -199,7 +199,7 @@ static std::string shape(cudnnFilterDescriptor_t t, cudnnDataType_t* type)
return
shape
(
res
,
outDims
);
return
shape
(
res
,
outDims
);
};
};
static
std
::
string
shape
(
cudnnConvolutionDescriptor_t
convDesc
)
static
std
::
string
shape
(
cudnnConvolutionDescriptor_t
convDesc
,
int
dataTypecode
)
{
{
int
nDim
;
int
nDim
;
cudnnConvolutionMode_t
mode
;
cudnnConvolutionMode_t
mode
;
...
@@ -208,6 +208,9 @@ static std::string shape(cudnnConvolutionDescriptor_t convDesc)
...
@@ -208,6 +208,9 @@ static std::string shape(cudnnConvolutionDescriptor_t convDesc)
int
padA
[
5
];
int
padA
[
5
];
int
strideA
[
5
];
int
strideA
[
5
];
int
dilationA
[
5
];
int
dilationA
[
5
];
/* Data type configuration. Format: " -<dtype><precision>" with dtype and precision in {h, f, d},
* h for half (float16), f for float (float32), d for double (float64). */
char
data_type_configuration
[
5
];
checkCudnnStatus
(
checkCudnnStatus
(
cudnnGetConvolutionNdDescriptor
(
convDesc
,
5
,
cudnnGetConvolutionNdDescriptor
(
convDesc
,
5
,
...
@@ -220,6 +223,27 @@ static std::string shape(cudnnConvolutionDescriptor_t convDesc)
...
@@ -220,6 +223,27 @@ static std::string shape(cudnnConvolutionDescriptor_t convDesc)
"error getting convolution description"
);
"error getting convolution description"
);
if
(
PyErr_Occurred
())
return
""
;
if
(
PyErr_Occurred
())
return
""
;
/* Build data type configuration string. */
data_type_configuration
[
0
]
=
' '
;
data_type_configuration
[
1
]
=
'-'
;
switch
(
dataTypecode
)
{
case
GA_HALF
:
data_type_configuration
[
2
]
=
'h'
;
break
;
case
GA_FLOAT
:
data_type_configuration
[
2
]
=
'f'
;
break
;
case
GA_DOUBLE
:
data_type_configuration
[
2
]
=
'd'
;
break
;
default
:
PyErr_SetString
(
PyExc_TypeError
,
"Unsupported data type in convolution."
);
return
""
;
}
switch
(
computeType
)
{
case
CUDNN_DATA_HALF
:
data_type_configuration
[
3
]
=
'h'
;
break
;
case
CUDNN_DATA_FLOAT
:
data_type_configuration
[
3
]
=
'f'
;
break
;
case
CUDNN_DATA_DOUBLE
:
data_type_configuration
[
3
]
=
'd'
;
break
;
default
:
PyErr_SetString
(
PyExc_TypeError
,
"Unsupported precision in convolution."
);
return
""
;
}
data_type_configuration
[
4
]
=
'\0'
;
return
(
std
::
string
(
"-mode "
)
+
return
(
std
::
string
(
"-mode "
)
+
((
mode
==
CUDNN_CONVOLUTION
)
?
"conv"
:
"cross"
)
+
((
mode
==
CUDNN_CONVOLUTION
)
?
"conv"
:
"cross"
)
+
" -pad "
+
" -pad "
+
...
@@ -227,7 +251,8 @@ static std::string shape(cudnnConvolutionDescriptor_t convDesc)
...
@@ -227,7 +251,8 @@ static std::string shape(cudnnConvolutionDescriptor_t convDesc)
" -subsample "
+
" -subsample "
+
shape
(
strideA
,
nDim
)
+
shape
(
strideA
,
nDim
)
+
" -dilation "
+
" -dilation "
+
shape
(
dilationA
,
nDim
));
shape
(
dilationA
,
nDim
)
+
data_type_configuration
);
}
}
static
bool
all_aligned
(
cudnnDataType_t
type
,
void
*
in
,
void
*
out
,
void
*
filter
)
static
bool
all_aligned
(
cudnnDataType_t
type
,
void
*
in
,
void
*
out
,
void
*
filter
)
...
@@ -253,7 +278,7 @@ static std::string dnn_conv_shape(cudnnTensorDescriptor_t inputDesc, PyGpuArrayO
...
@@ -253,7 +278,7 @@ static std::string dnn_conv_shape(cudnnTensorDescriptor_t inputDesc, PyGpuArrayO
return
""
;
return
""
;
std
::
string
shapeInput
=
shape
(
inputDesc
);
std
::
string
shapeInput
=
shape
(
inputDesc
);
std
::
string
shapeFilter
=
shape
(
filterDesc
,
&
dType
);
std
::
string
shapeFilter
=
shape
(
filterDesc
,
&
dType
);
std
::
string
shapeConvDesc
=
shape
(
convDesc
);
std
::
string
shapeConvDesc
=
shape
(
convDesc
,
input
->
ga
.
typecode
);
if
(
shapeInput
.
empty
()
||
shapeFilter
.
empty
()
||
shapeConvDesc
.
empty
())
if
(
shapeInput
.
empty
()
||
shapeFilter
.
empty
()
||
shapeConvDesc
.
empty
())
return
""
;
return
""
;
s
<<
"-g "
<<
groups
<<
" -dim "
<<
shapeInput
<<
" -filt "
<<
s
<<
"-g "
<<
groups
<<
" -dim "
<<
shapeInput
<<
" -filt "
<<
...
...
theano/gpuarray/c_code/dnn_fwd.c
浏览文件 @
1bc17311
...
@@ -352,7 +352,7 @@ APPLY_SPECIFIC(conv_fwd)(PyGpuArrayObject *input, PyGpuArrayObject *kerns,
...
@@ -352,7 +352,7 @@ APPLY_SPECIFIC(conv_fwd)(PyGpuArrayObject *input, PyGpuArrayObject *kerns,
}
}
fprintf
(
stderr
,
"(using %s%s %s%s%s, ws:%ld, hash:%s)
\n
"
,
fprintf
(
stderr
,
"(using %s%s %s%s%s, ws:%ld, hash:%s)
\n
"
,
algorithm_name
,
algorithm_name
,
mathtype
==
CUDNN_TENSOR_OP_MATH
?
"
[T]
"
:
""
,
mathtype
==
CUDNN_TENSOR_OP_MATH
?
"
(tensor_op)
"
:
""
,
params
->
choose_time
?
"(timed)"
:
""
,
params
->
choose_time
?
"(timed)"
:
""
,
reuse_algo
?
"(reused)"
:
""
,
reuse_algo
?
"(reused)"
:
""
,
use_cached
?
"(cache)"
:
""
,
use_cached
?
"(cache)"
:
""
,
...
...
theano/gpuarray/c_code/dnn_gi.c
浏览文件 @
1bc17311
...
@@ -170,7 +170,7 @@ APPLY_SPECIFIC(conv_gi)(PyGpuArrayObject *kerns, PyGpuArrayObject *output,
...
@@ -170,7 +170,7 @@ APPLY_SPECIFIC(conv_gi)(PyGpuArrayObject *kerns, PyGpuArrayObject *output,
char
pci_id
[
16
];
char
pci_id
[
16
];
gpucontext_property
(
c
->
ctx
,
GA_CTX_PROP_PCIBUSID
,
pci_id
);
gpucontext_property
(
c
->
ctx
,
GA_CTX_PROP_PCIBUSID
,
pci_id
);
// check out cache
// check out cache
hashkey
=
dnn_conv_shape
(
APPLY_SPECIFIC
(
input
),
*
input
,
APPLY_SPECIFIC
(
kerns
),
kerns
,
desc
,
output
,
groups
);
hashkey
=
dnn_conv_shape
(
APPLY_SPECIFIC
(
input
),
*
input
,
APPLY_SPECIFIC
(
kerns
),
kerns
,
desc
,
output
,
groups
);
if
(
hashkey
.
empty
())
{
if
(
hashkey
.
empty
())
{
cuda_exit
(
c
->
ctx
);
cuda_exit
(
c
->
ctx
);
return
1
;
return
1
;
...
@@ -307,13 +307,12 @@ APPLY_SPECIFIC(conv_gi)(PyGpuArrayObject *kerns, PyGpuArrayObject *output,
...
@@ -307,13 +307,12 @@ APPLY_SPECIFIC(conv_gi)(PyGpuArrayObject *kerns, PyGpuArrayObject *output,
cuda_exit
(
c
->
ctx
);
cuda_exit
(
c
->
ctx
);
return
1
;
return
1
;
}
}
// NB: This is printed only when algorithm is chosen at runtime.
fprintf
(
stderr
,
"(using %s%s %s%s%s, ws:%ld, hash:%s)
\n
"
,
fprintf
(
stderr
,
"(using %s %s%s%s%s, ws:%ld, hash:%s)
\n
"
,
algorithm_name
,
algorithm_name
,
mathtype
==
CUDNN_TENSOR_OP_MATH
?
"(tensor_op)"
:
""
,
params
->
choose_time
?
"(timed)"
:
""
,
params
->
choose_time
?
"(timed)"
:
""
,
reuse_algo
?
"(reused)"
:
""
,
reuse_algo
?
"(reused)"
:
""
,
use_cached
?
"(cache)"
:
""
,
use_cached
?
"(cache)"
:
""
,
mathtype
==
CUDNN_TENSOR_OP_MATH
?
"(tensor op)"
:
""
,
worksize
,
worksize
,
hashkey
.
c_str
()
hashkey
.
c_str
()
);
);
...
...
theano/gpuarray/c_code/dnn_gw.c
浏览文件 @
1bc17311
...
@@ -297,13 +297,12 @@ APPLY_SPECIFIC(conv_gw)(PyGpuArrayObject *input, PyGpuArrayObject *output,
...
@@ -297,13 +297,12 @@ APPLY_SPECIFIC(conv_gw)(PyGpuArrayObject *input, PyGpuArrayObject *output,
cuda_exit
(
c
->
ctx
);
cuda_exit
(
c
->
ctx
);
return
1
;
return
1
;
}
}
// NB: This is printed only when algorithm is chosen at runtime.
fprintf
(
stderr
,
"(using %s%s %s%s%s, ws:%ld, hash:%s)
\n
"
,
fprintf
(
stderr
,
"(using %s %s%s%s%s, ws:%ld, hash:%s)
\n
"
,
algorithm_name
,
algorithm_name
,
mathtype
==
CUDNN_TENSOR_OP_MATH
?
"(tensor_op)"
:
""
,
params
->
choose_time
?
"(timed)"
:
""
,
params
->
choose_time
?
"(timed)"
:
""
,
reuse_algo
?
"(reused)"
:
""
,
reuse_algo
?
"(reused)"
:
""
,
use_cached
?
"(cache)"
:
""
,
use_cached
?
"(cache)"
:
""
,
mathtype
==
CUDNN_TENSOR_OP_MATH
?
"(tensor op)"
:
""
,
worksize
,
worksize
,
hashkey
.
c_str
()
hashkey
.
c_str
()
);
);
...
...
theano/gpuarray/tests/test_dnn.py
浏览文件 @
1bc17311
...
@@ -2666,3 +2666,31 @@ class TestDnnConv3DRuntimeAlgorithms(TestDnnConv2DRuntimeAlgorithms):
...
@@ -2666,3 +2666,31 @@ class TestDnnConv3DRuntimeAlgorithms(TestDnnConv2DRuntimeAlgorithms):
(
1
,
[(
4
,
2
,
20
,
20
,
20
),
(
2
,
2
,
20
,
19
,
18
)]),
# cache should be used
(
1
,
[(
4
,
2
,
20
,
20
,
20
),
(
2
,
2
,
20
,
19
,
18
)]),
# cache should be used
(
1
,
[(
1
,
2
,
3
,
4
,
5
),
(
6
,
2
,
3
,
2
,
1
)])
(
1
,
[(
1
,
2
,
3
,
4
,
5
),
(
6
,
2
,
3
,
2
,
1
)])
]
]
def
test_conv_guess_once_with_dtypes
():
utt
.
seed_rng
()
inputs_shape
=
(
2
,
3
,
5
,
5
)
filters_shape
=
(
2
,
3
,
40
,
4
)
border_mode
=
'full'
def
get_function
(
dtype
,
precision
):
inputs_val
=
np
.
random
.
random
(
inputs_shape
)
.
astype
(
dtype
)
filters_val
=
np
.
random
.
random
(
filters_shape
)
.
astype
(
dtype
)
inputs_val
/=
10
filters_val
/=
10
inputs
=
theano
.
shared
(
inputs_val
)
filters
=
theano
.
shared
(
filters_val
)
conv
=
dnn
.
dnn_conv
(
img
=
inputs
,
kerns
=
filters
,
border_mode
=
border_mode
,
precision
=
precision
,
algo
=
'guess_once'
,
direction_hint
=
'forward!'
)
return
theano
.
function
([],
conv
)
f_true_half_config
=
get_function
(
'float16'
,
'float16'
)
f_pseudo_half_config
=
get_function
(
'float16'
,
'float32'
)
f_float_config
=
get_function
(
'float32'
,
'float32'
)
f_double_config
=
get_function
(
'float64'
,
'float64'
)
# Let's just see if everything runs without raising any exception.
f_true_half_config
()
f_pseudo_half_config
()
f_float_config
()
f_double_config
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论