Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Coulette
patapon
Commits
f2b3fae2
Commit
f2b3fae2
authored
Dec 06, 2017
by
Matthieu Boileau
Browse files
Use lbm_cl in a notebook
parent
e3962aa7
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
f2b3fae2
.ipynb_checkpoints/
lbm_cl.py
View file @
f2b3fae2
...
...
@@ -57,7 +57,8 @@ def solve_ocl(m = _m, n = _n, nx = _nx, ny = _ny,
Tmax
=
_Tmax
,
vmax
=
_vmax
,
dx
=
_dx
,
dy
=
_dy
,
dt
=
_dt
,
animate
=
False
):
animate
=
False
,
interactive
=
True
):
ff
=
"_F"
...
...
@@ -76,7 +77,7 @@ def solve_ocl(m = _m, n = _n, nx = _nx, ny = _ny,
source
=
source
.
replace
(
"_lambda_"
,
"("
+
str
(
vmax
)
+
ff
+
")"
)
source
=
source
.
replace
(
"_F"
,
""
)
print
(
source
)
#
print(source)
#exit(0)
...
...
@@ -113,6 +114,11 @@ def solve_ocl(m = _m, n = _n, nx = _nx, ny = _ny,
elapsed
=
0.
;
fn_cpu
=
np
.
empty
((
4
*
m
*
nx
*
ny
,
),
dtype
=
np
.
float64
)
if
animate
:
fig
=
plt
.
gcf
()
fig
.
show
()
fig
.
canvas
.
draw
()
print
(
"start OpenCL computations..."
)
while
t
<
Tmax
:
t
=
t
+
dt
...
...
@@ -124,16 +130,20 @@ def solve_ocl(m = _m, n = _n, nx = _nx, ny = _ny,
elapsed
+=
1e-9
*
(
event
.
profile
.
end
-
event
.
profile
.
start
)
# exchange buffer references for avoiding a copy
fn_gpu
,
fnp1_gpu
=
fnp1_gpu
,
fn_gpu
print
(
"iter="
,
iter
,
" t="
,
t
,
"elapsed (s)="
,
elapsed
)
if
iter
%
iterplot
==
0
and
animate
:
cl
.
enqueue_copy
(
queue
,
fn_cpu
,
fn_gpu
).
wait
()
wplot
=
np
.
reshape
(
fn_cpu
,
(
4
,
m
,
nx
,
ny
))
plt
.
clf
()
#plt.imshow(np.sum(wplot, axis = 0),vmin=0, vmax=1)
plt
.
imshow
(
np
.
sum
(
wplot
[:,
_ivplot
,
:,
:],
axis
=
0
))
plt
.
gca
().
invert_yaxis
()
plt
.
colorbar
()
plt
.
pause
(
0.01
)
title
=
"iter = {}, t = {:f}, elapsed (s) = {:f}"
.
format
(
iter
,
t
,
elapsed
)
if
animate
:
if
iter
%
iterplot
==
0
:
cl
.
enqueue_copy
(
queue
,
fn_cpu
,
fn_gpu
).
wait
()
wplot
=
np
.
reshape
(
fn_cpu
,
(
4
,
m
,
nx
,
ny
))
plt
.
clf
()
#plt.imshow(np.sum(wplot, axis = 0),vmin=0, vmax=1)
fig
.
suptitle
(
title
)
plt
.
imshow
(
np
.
sum
(
wplot
[:,
_ivplot
,
:,
:],
axis
=
0
))
plt
.
gca
().
invert_yaxis
()
plt
.
colorbar
()
fig
.
canvas
.
draw
()
else
:
print
(
title
,
end
=
'
\r
'
)
# copy OpenCL data to CPU and return the results
cl
.
enqueue_copy
(
queue
,
fn_cpu
,
fn_gpu
).
wait
()
...
...
@@ -141,28 +151,30 @@ def solve_ocl(m = _m, n = _n, nx = _nx, ny = _ny,
wplot_gpu
=
np
.
reshape
(
fn_cpu
,(
4
,
m
,
nx
,
ny
))
return
wplot_gpu
# gpu solve
wplot_gpu
=
solve_ocl
(
animate
=
True
)
#print(np.sum(wplot_gpu[:, _ivplot, :, :],axis=0))
plt
.
clf
()
#plt.imshow(np.sum(wplot_gpu[:, _ivplot, :, :],axis=0), vmin=0, vmax=1)
plt
.
imshow
(
np
.
sum
(
wplot_gpu
[:,
_ivplot
,
:,
:],
axis
=
0
))
plt
.
gca
().
invert_yaxis
()
plt
.
colorbar
()
plt
.
show
()
# for iv in range(4):
# plt.imshow(wplot_gpu[iv,:,:])
# plt.gca().invert_yaxis()
# plt.colorbar()
# plt.show()
# check difference
# plt.clf()
# plt.imshow(wplot_cpu-wplot_gpu)
# plt.gca().invert_yaxis()
# plt.colorbar()
# plt.show()
if
__name__
==
'__main__'
:
# gpu solve
wplot_gpu
=
solve_ocl
(
animate
=
False
)
#print(np.sum(wplot_gpu[:, _ivplot, :, :],axis=0))
plt
.
clf
()
#plt.imshow(np.sum(wplot_gpu[:, _ivplot, :, :],axis=0), vmin=0, vmax=1)
plt
.
imshow
(
np
.
sum
(
wplot_gpu
[:,
_ivplot
,
:,
:],
axis
=
0
))
plt
.
gca
().
invert_yaxis
()
plt
.
colorbar
()
plt
.
show
()
# for iv in range(4):
# plt.imshow(wplot_gpu[iv,:,:])
# plt.gca().invert_yaxis()
# plt.colorbar()
# plt.show()
# check difference
# plt.clf()
# plt.imshow(wplot_cpu-wplot_gpu)
# plt.gca().invert_yaxis()
# plt.colorbar()
# plt.show()
orszag-tang.ipynb
0 → 100644
View file @
f2b3fae2
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# lbm_cl\n",
"\n",
"## Orszag-Tang vortex on `gpu3.math.unistra.fr`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from lbm_cl import solve_ocl\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load OpenCL configuration on `gpu3`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"unset DISPLAY"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env XAUTHORITY=/tmp/x11-auth-file\n",
"%env GPU_DEVICE_ORDINAL=0,1,2,3\n",
"%env LD_LIBRARY_PATH=/opt/AMDAPPSDK-3.0/lib/x86_64:$LD_LIBRARY_PATH\n",
"%env CPATH=/opt/AMDAPPSDK-3.0/include:$CPATH"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Target a GPU device\n",
"\n",
"The following cell is equivalent to:\n",
"```bash\n",
"\n",
"Choose platform:\n",
"[0] <pyopencl.Platform 'AMD Accelerated Parallel Processing' at 0x7f0b44371430>\n",
"Choice [0]:\n",
"Choose device(s):\n",
"[0] <pyopencl.Device 'Redwood' on 'AMD Accelerated Parallel Processing' at 0x35f8690>\n",
"[1] <pyopencl.Device 'Tahiti' on 'AMD Accelerated Parallel Processing' at 0x3ce9ec0>\n",
"[2] <pyopencl.Device 'Tahiti' on 'AMD Accelerated Parallel Processing' at 0x3a864e0>\n",
"[3] <pyopencl.Device 'Tahiti' on 'AMD Accelerated Parallel Processing' at 0x3f79ed0>\n",
"[4] <pyopencl.Device 'Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz' on 'AMD Accelerated Parallel Processing' at 0x49d2e40>\n",
"Choice, comma-separated [0]:1\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env PYOPENCL_CTX=0:1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run computation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib notebook\n",
"%timeit wplot_gpu = solve_ocl(animate=False)\n",
"plt.clf()\n",
"plt.imshow(np.sum(wplot_gpu[:, 0, :, :],axis=0))\n",
"plt.gca().invert_yaxis()\n",
"plt.colorbar()\n",
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:markdown id: tags:
# lbm_cl
## Orszag-Tang vortex on `gpu3.math.unistra.fr`
%% Cell type:code id: tags:
```
python
from
lbm_cl
import
solve_ocl
import
matplotlib.pyplot
as
plt
import
numpy
as
np
```
%% Cell type:markdown id: tags:
### Load OpenCL configuration on `gpu3`
%% Cell type:code id: tags:
```
python
%%
bash
unset
DISPLAY
```
%% Cell type:code id: tags:
```
python
%
env
XAUTHORITY
=/
tmp
/
x11
-
auth
-
file
%
env
GPU_DEVICE_ORDINAL
=
0
,
1
,
2
,
3
%
env
LD_LIBRARY_PATH
=/
opt
/
AMDAPPSDK
-
3.0
/
lib
/
x86_64
:
$
LD_LIBRARY_PATH
%
env
CPATH
=/
opt
/
AMDAPPSDK
-
3.0
/
include
:
$
CPATH
```
%% Cell type:markdown id: tags:
### Target a GPU device
The following cell is equivalent to:
```
bash
Choose platform:
[
0] <pyopencl.Platform
'AMD Accelerated Parallel Processing'
at 0x7f0b44371430>
Choice
[
0]:
Choose device
(
s
)
:
[
0] <pyopencl.Device
'Redwood'
on
'AMD Accelerated Parallel Processing'
at 0x35f8690>
[
1] <pyopencl.Device
'Tahiti'
on
'AMD Accelerated Parallel Processing'
at 0x3ce9ec0>
[
2] <pyopencl.Device
'Tahiti'
on
'AMD Accelerated Parallel Processing'
at 0x3a864e0>
[
3] <pyopencl.Device
'Tahiti'
on
'AMD Accelerated Parallel Processing'
at 0x3f79ed0>
[
4] <pyopencl.Device
'Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz'
on
'AMD Accelerated Parallel Processing'
at 0x49d2e40>
Choice, comma-separated
[
0]:1
```
%% Cell type:code id: tags:
```
python
%
env
PYOPENCL_CTX
=
0
:
1
```
%% Cell type:markdown id: tags:
### Run computation
%% Cell type:code id: tags:
```
python
%
matplotlib
notebook
%
timeit
wplot_gpu
=
solve_ocl
(
animate
=
False
)
plt
.
clf
()
plt
.
imshow
(
np
.
sum
(
wplot_gpu
[:,
0
,
:,
:],
axis
=
0
))
plt
.
gca
().
invert_yaxis
()
plt
.
colorbar
()
plt
.
show
()
```
requirements.txt
0 → 100644
View file @
f2b3fae2
matplotlib
pyopencl
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment