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
Kaushik Kulkarni
loopy
Commits
b66344e0
Commit
b66344e0
authored
7 years ago
by
Matt Wala
Browse files
Options
Downloads
Patches
Plain Diff
Numpy execution: Enable support for relaxed stride checks (closes #121).
parent
ed139ad5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
loopy/target/execution.py
+17
-5
17 additions, 5 deletions
loopy/target/execution.py
test/test_loopy.py
+20
-0
20 additions, 0 deletions
test/test_loopy.py
with
37 additions
and
5 deletions
loopy/target/execution.py
+
17
−
5
View file @
b66344e0
...
@@ -363,6 +363,10 @@ class ExecutionWrapperGeneratorBase(object):
...
@@ -363,6 +363,10 @@ class ExecutionWrapperGeneratorBase(object):
from
loopy.types
import
NumpyType
from
loopy.types
import
NumpyType
gen
(
"
# {{{ set up array arguments
"
)
gen
(
"
# {{{ set up array arguments
"
)
gen
(
""
)
gen
(
"
def _lpy_filter_stride(shape, stride):
"
)
gen
(
"
return tuple(s for dim, s in zip(shape, stride) if dim > 1)
"
)
gen
(
""
)
gen
(
""
)
if
not
options
.
no_numpy
:
if
not
options
.
no_numpy
:
...
@@ -516,13 +520,21 @@ class ExecutionWrapperGeneratorBase(object):
...
@@ -516,13 +520,21 @@ class ExecutionWrapperGeneratorBase(object):
itemsize
=
kernel_arg
.
dtype
.
numpy_dtype
.
itemsize
itemsize
=
kernel_arg
.
dtype
.
numpy_dtype
.
itemsize
sym_strides
=
tuple
(
sym_strides
=
tuple
(
itemsize
*
s_i
for
s_i
in
arg
.
unvec_strides
)
itemsize
*
s_i
for
s_i
in
arg
.
unvec_strides
)
gen
(
"
if %s.strides != %s:
"
gen
(
"
if _lpy_filter_stride(%s.shape, %s.strides) !=
"
%
(
arg
.
name
,
strify
(
sym_strides
)))
"
_lpy_filter_stride(%s.shape, %s):
"
%
(
arg
.
name
,
arg
.
name
,
arg
.
name
,
strify
(
sym_strides
)))
with
Indentation
(
gen
):
with
Indentation
(
gen
):
gen
(
"
raise TypeError(
\"
strides mismatch on
"
gen
(
"
raise TypeError(
\"
strides mismatch on
"
"
argument
'
%s
'
(got: %%s, expected: %%s)
\"
"
"
argument
'
%s
'
"
"
%% (%s.strides, %s))
"
"
(after removing unit length dims,
"
%
(
arg
.
name
,
arg
.
name
,
strify
(
sym_strides
)))
"
got: %%s, expected: %%s)
\"
"
"
%% (_lpy_filter_stride(%s.shape, %s.strides),
"
"
_lpy_filter_stride(%s.shape, %s)))
"
%
(
arg
.
name
,
arg
.
name
,
arg
.
name
,
arg
.
name
,
strify
(
sym_strides
)))
if
not
arg
.
allows_offset
:
if
not
arg
.
allows_offset
:
gen
(
"
if hasattr(%s,
'
offset
'
) and %s.offset:
"
%
(
gen
(
"
if hasattr(%s,
'
offset
'
) and %s.offset:
"
%
(
...
...
This diff is collapsed.
Click to expand it.
test/test_loopy.py
+
20
−
0
View file @
b66344e0
...
@@ -2746,6 +2746,26 @@ def test_arg_inference_for_predicates():
...
@@ -2746,6 +2746,26 @@ def test_arg_inference_for_predicates():
assert
knl
.
arg_dict
[
"
incr
"
].
shape
==
(
10
,)
assert
knl
.
arg_dict
[
"
incr
"
].
shape
==
(
10
,)
def
test_relaxed_stride_checks
(
ctx_factory
):
# Check that loopy is compatible with numpy's relaxed stride rules.
ctx
=
ctx_factory
()
knl
=
lp
.
make_kernel
(
"
{[i,j]: 0 <= i <= n and 0 <= j <= m}
"
,
"""
a[i] = sum(j, A[i,j] * b[j])
"""
)
with
cl
.
CommandQueue
(
ctx
)
as
queue
:
A
=
np
.
zeros
((
1
,
10
),
order
=
"
F
"
)
# Force convert A to C order. numpy will preserve strides in this case.
A
=
np
.
array
(
A
,
copy
=
False
,
order
=
"
C
"
)
b
=
np
.
zeros
(
10
,
dtype
=
np
.
float64
)
evt
,
(
a
,)
=
knl
(
queue
,
A
=
A
,
b
=
b
)
assert
a
==
0
def
test_add_prefetch_works_in_lhs_index
():
def
test_add_prefetch_works_in_lhs_index
():
knl
=
lp
.
make_kernel
(
knl
=
lp
.
make_kernel
(
"
{ [n,k,l,k1,l1,k2,l2]:
"
"
{ [n,k,l,k1,l1,k2,l2]:
"
...
...
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