Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
patapon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
David Coulette
patapon
Commits
f2b3fae2
Commit
f2b3fae2
authored
Dec 06, 2017
by
Matthieu Boileau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use lbm_cl in a notebook
parent
e3962aa7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
177 additions
and
35 deletions
+177
-35
.gitignore
.gitignore
+1
-0
lbm_cl.py
lbm_cl.py
+47
-35
orszag-tang.ipynb
orszag-tang.ipynb
+127
-0
requirements.txt
requirements.txt
+2
-0
No files found.
.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
}
requirements.txt
0 → 100644
View file @
f2b3fae2
matplotlib
pyopencl
Write
Preview
Markdown
is supported
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