Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
psaap3-weno
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Klöckner
psaap3-weno
Commits
2d875121
Commit
2d875121
authored
5 years ago
by
Timothy A. Smith
Browse files
Options
Downloads
Patches
Plain Diff
get rid of LoopyFixture class
parent
7c415f1e
No related branches found
No related tags found
1 merge request
!8
Test refactoring
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fixtures.py
+48
-51
48 additions, 51 deletions
fixtures.py
test.py
+12
-15
12 additions, 15 deletions
test.py
with
60 additions
and
66 deletions
fixtures.py
+
48
−
51
View file @
2d875121
...
...
@@ -8,6 +8,16 @@ import loopy as lp
from
pytest
import
approx
_WENO_PRG
=
[]
_QUEUE
=
[]
def
get_queue
(
ctx_factory
):
if
not
_QUEUE
:
ctx
=
ctx_factory
()
_QUEUE
.
append
(
cl
.
CommandQueue
(
ctx
))
return
_QUEUE
[
0
]
def
with_root_kernel
(
prg
,
root_name
):
# FIXME This is a little less beautiful than it could be
new_prg
=
prg
.
copy
(
name
=
root_name
)
...
...
@@ -20,70 +30,57 @@ def with_root_kernel(prg, root_name):
return
new_prg
class
LoopyFixture
:
_WENO_PRG
=
[]
_QUEUE
=
[]
def
__init__
(
self
):
self
.
prg
=
self
.
get_weno_program
()
def
get_weno_program
(
self
):
if
self
.
_WENO_PRG
:
return
self
.
_WENO_PRG
[
0
]
fn
=
"
WENO.F90
"
def
get_weno_program
():
if
_WENO_PRG
:
return
_WENO_PRG
[
0
]
with
open
(
fn
,
"
r
"
)
as
infile
:
infile_content
=
infile
.
read
()
fn
=
"
WENO.F90
"
prg
=
lp
.
parse_transformed_fortran
(
infile_content
,
filename
=
fn
)
self
.
_WENO_PRG
.
append
(
prg
)
return
prg
with
open
(
fn
,
"
r
"
)
as
infile
:
infile_content
=
infile
.
read
()
def
get_queue
(
self
,
ctx_factory
):
if
not
self
.
_QUEUE
:
ctx
=
ctx_factory
()
self
.
_QUEUE
.
append
(
cl
.
CommandQueue
(
ctx
))
return
self
.
_QUEUE
[
0
]
prg
=
lp
.
parse_transformed_fortran
(
infile_content
,
filename
=
fn
)
_WENO_PRG
.
append
(
prg
)
return
prg
def
random_array
(
self
,
*
args
):
return
np
.
random
.
random_sample
(
args
).
astype
(
np
.
float32
).
copy
(
order
=
"
F
"
)
def
random_array
(
*
args
):
return
np
.
random
.
random_sample
(
args
).
astype
(
np
.
float32
).
copy
(
order
=
"
F
"
)
def
mult_mat_vec
(
self
,
ctx_factory
,
alpha
,
a
,
b
):
queue
=
self
.
get_queue
(
ctx_factory
)
def
mult_mat_vec
(
ctx_factory
,
alpha
,
a
,
b
):
queue
=
get_queue
(
ctx_factory
)
c_dev
=
cl
.
array
.
empty
(
queue
,
10
,
dtype
=
np
.
float32
)
c_dev
=
cl
.
array
.
empty
(
queue
,
10
,
dtype
=
np
.
float32
)
prg
=
with_root_kernel
(
self
.
prg
,
"
mult_mat_vec
"
)
prg
(
queue
,
a
=
a
,
b
=
b
,
c
=
c_dev
,
alpha
=
alpha
)
prg
=
with_root_kernel
(
get_weno_program
()
,
"
mult_mat_vec
"
)
prg
(
queue
,
a
=
a
,
b
=
b
,
c
=
c_dev
,
alpha
=
alpha
)
return
c_dev
.
get
()
return
c_dev
.
get
()
def
compute_flux_derivatives
(
self
,
ctx_factory
,
nvars
,
ndim
,
nx
,
ny
,
nz
,
states
,
fluxes
,
metrics
,
metric_jacobians
):
def
compute_flux_derivatives
(
ctx_factory
,
nvars
,
ndim
,
nx
,
ny
,
nz
,
states
,
fluxes
,
metrics
,
metric_jacobians
):
queue
=
self
.
get_queue
(
ctx_factory
)
queue
=
get_queue
(
ctx_factory
)
prg
=
self
.
prg
cfd
=
prg
[
"
compute_flux_derivatives
"
]
prg
=
get_weno_program
()
cfd
=
prg
[
"
compute_flux_derivatives
"
]
cfd
=
lp
.
assume
(
cfd
,
"
nx > 0 and ny > 0 and nz > 0
"
)
cfd
=
lp
.
assume
(
cfd
,
"
nx > 0 and ny > 0 and nz > 0
"
)
cfd
=
lp
.
set_temporary_scope
(
cfd
,
"
flux_derivatives_generalized
"
,
lp
.
AddressSpace
.
GLOBAL
)
cfd
=
lp
.
set_temporary_scope
(
cfd
,
"
generalized_fluxes
"
,
lp
.
AddressSpace
.
GLOBAL
)
cfd
=
lp
.
set_temporary_scope
(
cfd
,
"
weno_flux_tmp
"
,
lp
.
AddressSpace
.
GLOBAL
)
cfd
=
lp
.
set_temporary_scope
(
cfd
,
"
flux_derivatives_generalized
"
,
lp
.
AddressSpace
.
GLOBAL
)
cfd
=
lp
.
set_temporary_scope
(
cfd
,
"
generalized_fluxes
"
,
lp
.
AddressSpace
.
GLOBAL
)
cfd
=
lp
.
set_temporary_scope
(
cfd
,
"
weno_flux_tmp
"
,
lp
.
AddressSpace
.
GLOBAL
)
prg
=
prg
.
with_kernel
(
cfd
)
prg
=
prg
.
with_kernel
(
cfd
)
flux_derivatives_dev
=
cl
.
array
.
empty
(
queue
,
(
nvars
,
ndim
,
nx
+
6
,
ny
+
6
,
nz
+
6
),
dtype
=
np
.
float32
,
order
=
"
F
"
)
flux_derivatives_dev
=
cl
.
array
.
empty
(
queue
,
(
nvars
,
ndim
,
nx
+
6
,
ny
+
6
,
nz
+
6
),
dtype
=
np
.
float32
,
order
=
"
F
"
)
prg
(
queue
,
nvars
=
nvars
,
ndim
=
ndim
,
states
=
states
,
fluxes
=
fluxes
,
metrics
=
metrics
,
metric_jacobians
=
metric_jacobians
,
flux_derivatives
=
flux_derivatives_dev
)
return
flux_derivatives_dev
.
get
()
prg
(
queue
,
nvars
=
nvars
,
ndim
=
ndim
,
states
=
states
,
fluxes
=
fluxes
,
metrics
=
metrics
,
metric_jacobians
=
metric_jacobians
,
flux_derivatives
=
flux_derivatives_dev
)
return
flux_derivatives_dev
.
get
()
This diff is collapsed.
Click to expand it.
test.py
+
12
−
15
View file @
2d875121
...
...
@@ -14,17 +14,14 @@ from pyopencl.tools import ( # noqa
pytest_generate_tests_for_pyopencl
as
pytest_generate_tests
)
from
fixtures
import
LoopyFixture
f
=
LoopyFixture
()
import
fixtures
def
test_matvec
(
ctx_factory
):
a
=
f
.
random_array
(
10
,
10
)
b
=
f
.
random_array
(
10
)
a
=
f
ixtures
.
random_array
(
10
,
10
)
b
=
f
ixtures
.
random_array
(
10
)
c
=
f
.
mult_mat_vec
(
ctx_factory
,
a
=
a
,
b
=
b
,
alpha
=
1.0
)
c
=
f
ixtures
.
mult_mat_vec
(
ctx_factory
,
a
=
a
,
b
=
b
,
alpha
=
1.0
)
assert
la
.
norm
(
a
@b
-
c
,
2
)
/
la
.
norm
(
c
)
<
1e-5
...
...
@@ -38,12 +35,12 @@ def test_compute_flux_derivatives(ctx_factory):
ny
=
10
nz
=
10
states
=
f
.
random_array
(
nvars
,
nx
+
6
,
ny
+
6
,
nz
+
6
)
fluxes
=
f
.
random_array
(
nvars
,
ndim
,
nx
+
6
,
ny
+
6
,
nz
+
6
)
metrics
=
f
.
random_array
(
ndim
,
ndim
,
nx
+
6
,
ny
+
6
,
nz
+
6
)
metric_jacobians
=
f
.
random_array
(
nx
+
6
,
ny
+
6
,
nz
+
6
)
states
=
f
ixtures
.
random_array
(
nvars
,
nx
+
6
,
ny
+
6
,
nz
+
6
)
fluxes
=
f
ixtures
.
random_array
(
nvars
,
ndim
,
nx
+
6
,
ny
+
6
,
nz
+
6
)
metrics
=
f
ixtures
.
random_array
(
ndim
,
ndim
,
nx
+
6
,
ny
+
6
,
nz
+
6
)
metric_jacobians
=
f
ixtures
.
random_array
(
nx
+
6
,
ny
+
6
,
nz
+
6
)
f
.
compute_flux_derivatives
(
ctx_factory
,
f
ixtures
.
compute_flux_derivatives
(
ctx_factory
,
nvars
=
nvars
,
ndim
=
ndim
,
nx
=
nx
,
ny
=
ny
,
nz
=
nz
,
states
=
states
,
fluxes
=
fluxes
,
metrics
=
metrics
,
metric_jacobians
=
metric_jacobians
)
...
...
@@ -55,7 +52,7 @@ def f_array(queue, *shape):
def
get_gpu_transformed_weno
():
prg
=
f
.
prg
prg
=
f
ixtures
.
get_weno_program
()
cfd
=
prg
[
"
compute_flux_derivatives
"
]
...
...
@@ -104,7 +101,7 @@ def test_compute_flux_derivatives_gpu(ctx_factory):
prg
=
get_gpu_transformed_weno
()
queue
=
f
.
get_queue
(
ctx_factory
)
queue
=
f
ixtures
.
get_queue
(
ctx_factory
)
ndim
=
3
nvars
=
5
...
...
@@ -144,7 +141,7 @@ def benchmark_compute_flux_derivatives_gpu(ctx_factory):
prg
=
get_gpu_transformed_weno
()
queue
=
f
.
get_queue
(
ctx_factory
)
queue
=
f
ixtures
.
get_queue
(
ctx_factory
)
ndim
=
3
nvars
=
5
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment