Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4e53fc30
提交
4e53fc30
authored
12月 02, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make variable name more descriptive
上级
cd037afb
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
20 行删除
+22
-20
nnet.py
theano/sandbox/gpuarray/nnet.py
+22
-20
没有找到文件。
theano/sandbox/gpuarray/nnet.py
浏览文件 @
4e53fc30
import
numpy
from
theano
import
Op
,
Apply
from
theano
import
Op
,
Apply
from
theano.compat.six
import
StringIO
from
theano.compat.six
import
StringIO
...
@@ -44,31 +46,31 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias(Op):
...
@@ -44,31 +46,31 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias(Op):
def
c_headers
(
self
):
def
c_headers
(
self
):
return
[
'cuda.h'
,
'<compyte/extension.h>'
,
'<compyte/numpy_compat.h>'
]
return
[
'cuda.h'
,
'<compyte/extension.h>'
,
'<compyte/numpy_compat.h>'
]
def
c_support_code_apply
(
self
,
node
):
def
c_support_code_apply
(
self
,
node
,
nodename
):
dtype
0
=
node
.
inputs
[
0
]
.
dtype
dtype
_x
=
node
.
inputs
[
0
]
.
dtype
dtype
1
=
node
.
inputs
[
1
]
.
dtype
dtype
_b
=
node
.
inputs
[
1
]
.
dtype
dtype
2
=
node
.
inputs
[
2
]
.
dtype
dtype
_y_idx
=
node
.
inputs
[
2
]
.
dtype
return
"""
return
"""
__global__ void k_xent_sm_1hot_bias(int M, int N,
__global__ void k_xent_sm_1hot_bias
_
%(nodename)
s
(int M, int N,
const npy_
%(dtype
0
)
s* x_data, int xs0, int xs1,
const npy_
%(dtype
_x
)
s* x_data, int xs0, int xs1,
const npy_
%(dtype
1
)
s* b, int bs0,
const npy_
%(dtype
_b
)
s* b, int bs0,
const npy_
%(dtype
2
)
s* y_idx_data, int y_idxs0,
const npy_
%(dtype
_y_idx
)
s* y_idx_data, int y_idxs0,
npy_
%(dtype)
s* nll_data, int nlls0,
npy_
%(dtype
_x
)
s* nll_data, int nlls0,
npy_
%(dtype)
s* sm_data, int sms0, int sms1,
npy_
%(dtype
_x
)
s* sm_data, int sms0, int sms1,
npy_
%(dtype)
s* am_data, int ams0)
npy_
%(dtype
_y_idx
)
s* am_data, int ams0)
{
{
for (int row = blockIdx.x; row < M; row += gridDim.x){
for (int row = blockIdx.x; row < M; row += gridDim.x){
const npy_
%(dtype
0
)
s* x = x_data + xs0 * row;
const npy_
%(dtype
_x
)
s* x = x_data + xs0 * row;
const
int y_idx = (int)
y_idx_data[row * y_idxs0];
const
npy_
%(dtype_y_idx)
s y_idx =
y_idx_data[row * y_idxs0];
npy_
%(dtype
0
)
s* sm = sm_data + sms0 * row;
npy_
%(dtype
_x
)
s* sm = sm_data + sms0 * row;
npy_
%(dtype
0
)
s sum = 0.0;
npy_
%(dtype
_x
)
s sum = 0.0;
int row_max_j = 0;
int row_max_j = 0;
npy_
%(dtype
0
)
s row_max = x[0] + b[0];
npy_
%(dtype
_x
)
s row_max = x[0] + b[0];
for (int j = 1; j < N; ++j)
for (int j = 1; j < N; ++j)
{
{
npy_
%(dtype
0
)
s row_ij = x[j*xs1] + b[j*bs0];
npy_
%(dtype
_x
)
s row_ij = x[j*xs1] + b[j*bs0];
//todo: store to shared memory
//todo: store to shared memory
row_max_j = (row_ij > row_max) ? j : row_max_j;
row_max_j = (row_ij > row_max) ? j : row_max_j;
row_max = (row_ij > row_max) ? row_ij : row_max;
row_max = (row_ij > row_max) ? row_ij : row_max;
...
@@ -76,12 +78,12 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias(Op):
...
@@ -76,12 +78,12 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias(Op):
//compute the exp
//compute the exp
for (int j = 0; j < N; ++j)
for (int j = 0; j < N; ++j)
{
{
npy_
%(dtype
0
)
s row_ij = x[j*xs1] + b[j*bs0];
npy_
%(dtype
_x
)
s row_ij = x[j*xs1] + b[j*bs0];
npy_
%(dtype
0
)
s sm_ij = exp(row_ij - row_max);
npy_
%(dtype
_x
)
s sm_ij = exp(row_ij - row_max);
sum += sm_ij;
sum += sm_ij;
sm[j * sms1] = sm_ij;
sm[j * sms1] = sm_ij;
}
}
npy_
%(dtype
0
)
s sum_inv = 1.0 / sum;
npy_
%(dtype
_x
)
s sum_inv = 1.0 / sum;
for (int j = 0; j < N; ++j)
for (int j = 0; j < N; ++j)
{
{
sm[j * sms1] *= sum_inv;
sm[j * sms1] *= sum_inv;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论