Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
loopy
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
Ben Sepanski
loopy
Commits
4ebc1af1
Commit
4ebc1af1
authored
12 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Make checking in CompiledKernel use assert.
parent
06c0bfc2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
loopy/compiled.py
+34
-24
34 additions, 24 deletions
loopy/compiled.py
with
34 additions
and
24 deletions
loopy/compiled.py
+
34
−
24
View file @
4ebc1af1
...
@@ -7,6 +7,36 @@ import numpy as np
...
@@ -7,6 +7,36 @@ import numpy as np
# {{{ argument checking
def
_arg_matches_spec
(
arg
,
val
,
other_args
):
import
loopy
as
lp
if
isinstance
(
arg
,
lp
.
ArrayArg
):
from
pymbolic
import
evaluate
shape
=
evaluate
(
arg
.
shape
,
other_args
)
if
arg
.
dtype
!=
val
.
dtype
:
raise
TypeError
(
"
dtype mismatch on argument
'
%s
'
"
"
(got: %s, expected: %s)
"
%
(
arg
.
name
,
val
.
dtype
,
arg
.
dtype
))
if
shape
!=
val
.
shape
:
raise
TypeError
(
"
shape mismatch on argument
'
%s
'
"
"
(got: %s, expected: %s)
"
%
(
arg
.
name
,
val
.
shape
,
shape
))
if
arg
.
order
==
"
F
"
and
not
val
.
flags
.
f_contiguous
:
raise
TypeError
(
"
order mismatch on argument
'
%s
'
"
"
(expected Fortran-contiguous, but isn
'
t)
"
%
(
arg
.
name
))
if
arg
.
order
==
"
C
"
and
not
val
.
flags
.
c_contiguous
:
print
id
(
val
),
val
.
flags
raise
TypeError
(
"
order mismatch on argument
'
%s
'
"
"
(expected C-contiguous, but isn
'
t)
"
%
(
arg
.
name
))
return
True
# }}}
# {{{ compiled kernel object
# {{{ compiled kernel object
class
CompiledKernel
:
class
CompiledKernel
:
...
@@ -101,12 +131,11 @@ class CompiledKernel:
...
@@ -101,12 +131,11 @@ class CompiledKernel:
allocator
=
kwargs
.
pop
(
"
allocator
"
,
None
)
allocator
=
kwargs
.
pop
(
"
allocator
"
,
None
)
wait_for
=
kwargs
.
pop
(
"
wait_for
"
,
None
)
wait_for
=
kwargs
.
pop
(
"
wait_for
"
,
None
)
out_host
=
kwargs
.
pop
(
"
out_host
"
,
None
)
out_host
=
kwargs
.
pop
(
"
out_host
"
,
None
)
check
=
kwargs
.
pop
(
"
check
"
,
True
)
import
loopy
as
lp
import
loopy
as
lp
if
check
and
self
.
needs_check
:
if
self
.
needs_check
:
lp
.
check_kernels
([
self
.
kernel
],
kwargs
)
assert
len
(
list
(
lp
.
check_kernels
([
self
.
kernel
],
kwargs
)
))
==
1
self
.
needs_check
=
False
self
.
needs_check
=
False
...
@@ -133,27 +162,8 @@ class CompiledKernel:
...
@@ -133,27 +162,8 @@ class CompiledKernel:
shape
=
evaluate
(
arg
.
shape
,
kwargs
)
shape
=
evaluate
(
arg
.
shape
,
kwargs
)
val
=
cl_array
.
empty
(
queue
,
shape
,
arg
.
dtype
,
order
=
arg
.
order
,
val
=
cl_array
.
empty
(
queue
,
shape
,
arg
.
dtype
,
order
=
arg
.
order
,
allocator
=
allocator
)
allocator
=
allocator
)
elif
check
:
else
:
if
isinstance
(
arg
,
lp
.
ArrayArg
):
assert
_arg_matches_spec
(
arg
,
val
,
kwargs
)
from
pymbolic
import
evaluate
shape
=
evaluate
(
arg
.
shape
,
kwargs
)
if
arg
.
dtype
!=
val
.
dtype
:
raise
TypeError
(
"
dtype mismatch on argument
'
%s
'"
"
(got: %s, expected: %s)
"
%
(
arg
.
name
,
val
.
dtype
,
arg
.
dtype
))
if
shape
!=
val
.
shape
:
raise
TypeError
(
"
shape mismatch on argument
'
%s
'"
"
(got: %s, expected: %s)
"
%
(
arg
.
name
,
val
.
shape
,
shape
))
if
arg
.
order
==
"
F
"
and
not
val
.
flags
.
f_contiguous
:
raise
TypeError
(
"
order mismatch on argument
'
%s
'"
"
(expected Fortran-contiguous, but isn
'
t)
"
%
(
arg
.
name
))
if
arg
.
order
==
"
C
"
and
not
val
.
flags
.
c_contiguous
:
raise
TypeError
(
"
order mismatch on argument
'
%s
'"
"
(expected C-contiguous, but isn
'
t)
"
%
(
arg
.
name
))
# automatically transfer host-side arrays
# automatically transfer host-side arrays
if
isinstance
(
arg
,
lp
.
ArrayArg
):
if
isinstance
(
arg
,
lp
.
ArrayArg
):
...
...
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