Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
af5457e1
提交
af5457e1
authored
6月 13, 2011
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added missing example file and a few fix to the tutorial slide.
上级
7b3aa573
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
40 行增加
和
5 行删除
+40
-5
logreg_example.py
doc/hpcs2011_tutorial/logreg_example.py
+12
-2
presentation.tex
doc/hpcs2011_tutorial/presentation.tex
+3
-3
pycuda_simple.py
doc/hpcs2011_tutorial/pycuda_simple.py
+25
-0
没有找到文件。
doc/hpcs2011_tutorial/logreg_example.py
浏览文件 @
af5457e1
...
@@ -6,7 +6,7 @@ rng = numpy.random
...
@@ -6,7 +6,7 @@ rng = numpy.random
N
=
400
N
=
400
feats
=
784
feats
=
784
D
=
(
rng
.
randn
(
N
,
feats
)
.
astype
(
theano
.
config
.
floatX
),
rng
.
randint
(
size
=
N
,
low
=
0
,
high
=
2
)
.
astype
(
theano
.
config
.
floatX
))
D
=
(
rng
.
randn
(
N
,
feats
)
.
astype
(
theano
.
config
.
floatX
),
rng
.
randint
(
size
=
N
,
low
=
0
,
high
=
2
)
.
astype
(
theano
.
config
.
floatX
))
training_steps
=
10
training_steps
=
10
0
# Declare Theano symbolic variables
# Declare Theano symbolic variables
x
=
T
.
matrix
(
"x"
)
x
=
T
.
matrix
(
"x"
)
...
@@ -30,11 +30,21 @@ gw,gb = T.grad(cost, [w,b])
...
@@ -30,11 +30,21 @@ gw,gb = T.grad(cost, [w,b])
train
=
theano
.
function
(
train
=
theano
.
function
(
inputs
=
[
x
,
y
],
inputs
=
[
x
,
y
],
outputs
=
[
prediction
,
xent
],
outputs
=
[
prediction
,
xent
],
updates
=
{
w
:
w
-
0.
1
*
gw
,
b
:
b
-
0.
1
*
gb
},
updates
=
{
w
:
w
-
0.
01
*
gw
,
b
:
b
-
0.0
1
*
gb
},
name
=
"train"
)
name
=
"train"
)
predict
=
theano
.
function
(
inputs
=
[
x
],
outputs
=
prediction
,
predict
=
theano
.
function
(
inputs
=
[
x
],
outputs
=
prediction
,
name
=
"predict"
)
name
=
"predict"
)
if
any
(
[
x
.
op
.
__class__
.
__name__
==
'Gemv'
for
x
in
train
.
maker
.
env
.
toposort
()]):
print
'Used the cpu'
elif
any
(
[
x
.
op
.
__class__
.
__name__
==
'GpuGemm'
for
x
in
train
.
maker
.
env
.
toposort
()]):
print
'Used the gpu'
else
:
print
'ERROR, not able to tell if theano used the cpu or the gpu'
print
train
.
maker
.
env
.
toposort
()
for
i
in
range
(
training_steps
):
for
i
in
range
(
training_steps
):
pred
,
err
=
train
(
D
[
0
],
D
[
1
])
pred
,
err
=
train
(
D
[
0
],
D
[
1
])
print
"Final model:"
print
"Final model:"
...
...
doc/hpcs2011_tutorial/presentation.tex
浏览文件 @
af5457e1
...
@@ -522,7 +522,7 @@ rng = numpy.random
...
@@ -522,7 +522,7 @@ rng = numpy.random
N = 400
N = 400
feats = 784
feats = 784
D = (rng.randn(N, feats), rng.randint(size=N,low=0, high=2))
D = (rng.randn(N, feats), rng.randint(size=N,low=0, high=2))
training
_
steps = 10
training
_
steps = 10
0
\end{Verbatim}
\end{Verbatim}
\end{frame}
\end{frame}
...
@@ -752,7 +752,7 @@ Computers in the class
...
@@ -752,7 +752,7 @@ Computers in the class
\end{itemize}
\end{itemize}
\vfill
\vfill
\begin{itemize}
\begin{itemize}
\item
Broadcastability must be specified when creating the variable
.
\item
Broadcastability must be specified when creating the variable
\item
The only shorcut with broadcastable dimensions are:
{
\bf
T.row
}
and
{
\bf
T.col
}
\item
The only shorcut with broadcastable dimensions are:
{
\bf
T.row
}
and
{
\bf
T.col
}
\item
For all others: T.tensor(dtype, broadcastable=
{
\bf
([False or True])*nd
}
)
\item
For all others: T.tensor(dtype, broadcastable=
{
\bf
([False or True])*nd
}
)
\end{itemize}
\end{itemize}
...
@@ -1337,7 +1337,7 @@ multiply_them(
...
@@ -1337,7 +1337,7 @@ multiply_them(
\begin{frame}
\begin{frame}
\frametitle
{
PyCUDA Exercises
}
\frametitle
{
PyCUDA Exercises
}
\begin{itemize}
\begin{itemize}
\item
Run the example
\item
Run the example
in the file pycuda
_
simple.py
\item
Modify and execute it to work for a matrix of 20
$
\times
$
10
\item
Modify and execute it to work for a matrix of 20
$
\times
$
10
\end{itemize}
\end{itemize}
\end{frame}
\end{frame}
...
...
doc/hpcs2011_tutorial/pycuda_simple.py
0 → 100644
浏览文件 @
af5457e1
import
pycuda.autoinit
import
pycuda.driver
as
drv
import
numpy
from
pycuda.compiler
import
SourceModule
mod
=
SourceModule
(
"""
__global__ void multiply_them(float *dest, float *a, float *b)
{
const int i = threadIdx.x;
dest[i] = a[i] * b[i];
}
"""
)
multiply_them
=
mod
.
get_function
(
"multiply_them"
)
a
=
numpy
.
random
.
randn
(
400
)
.
astype
(
numpy
.
float32
)
b
=
numpy
.
random
.
randn
(
400
)
.
astype
(
numpy
.
float32
)
dest
=
numpy
.
zeros_like
(
a
)
multiply_them
(
drv
.
Out
(
dest
),
drv
.
In
(
a
),
drv
.
In
(
b
),
block
=
(
400
,
1
,
1
),
grid
=
(
1
,
1
))
assert
numpy
.
allclose
(
dest
,
a
*
b
)
print
dest
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论