Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
dca00ef2
Commit
dca00ef2
authored
Sep 05, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memslice support for cython.parallel
parent
55fa9f1f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
7 deletions
+52
-7
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+8
-3
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+2
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+3
-0
tests/errors/e_cython_parallel.pyx
tests/errors/e_cython_parallel.pyx
+5
-0
tests/run/memslice.pyx
tests/run/memslice.pyx
+34
-3
No files found.
Cython/Compiler/Nodes.py
View file @
dca00ef2
...
...
@@ -6174,9 +6174,9 @@ class ParallelStatNode(StatNode, ParallelNode):
# By default all variables should have the same values as if
# executed sequentially
lastprivate
=
True
self
.
propagate_var_privatization
(
entry
,
op
,
lastprivate
)
self
.
propagate_var_privatization
(
entry
,
pos
,
op
,
lastprivate
)
def
propagate_var_privatization
(
self
,
entry
,
op
,
lastprivate
):
def
propagate_var_privatization
(
self
,
entry
,
pos
,
op
,
lastprivate
):
"""
Propagate the sharing attributes of a variable. If the privatization is
determined by a parent scope, done propagate further.
...
...
@@ -6230,6 +6230,11 @@ class ParallelStatNode(StatNode, ParallelNode):
# sum and j are undefined here
"""
self
.
privates
[
entry
]
=
(
op
,
lastprivate
)
if
entry
.
type
.
is_memoryviewslice
:
error
(
pos
,
"Memoryview slices can only be shared in parallel sections"
)
return
if
self
.
is_prange
:
if
not
self
.
is_parallel
and
entry
not
in
self
.
parent
.
assignments
:
# Parent is a parallel with block
...
...
@@ -6240,7 +6245,7 @@ class ParallelStatNode(StatNode, ParallelNode):
# We don't need to propagate privates, only reductions and
# lastprivates
if
parent
and
(
op
or
lastprivate
):
parent
.
propagate_var_privatization
(
entry
,
op
,
lastprivate
)
parent
.
propagate_var_privatization
(
entry
,
pos
,
op
,
lastprivate
)
def
_allocate_closure_temp
(
self
,
code
,
entry
):
"""
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
dca00ef2
...
...
@@ -1037,7 +1037,8 @@ class ParallelRangeTransform(CythonTransform, SkipDeclarations):
directive
=
directive
.
rstrip
(
'.'
)
cls
=
self
.
directive_to_node
.
get
(
directive
)
if
cls
is
None
:
if
cls
is
None
and
not
(
self
.
namenode_is_cython_module
and
self
.
parallel_directive
[
0
]
!=
'parallel'
):
error
(
node
.
pos
,
"Invalid directive: %s"
%
directive
)
self
.
namenode_is_cython_module
=
False
...
...
Cython/Compiler/PyrexTypes.py
View file @
dca00ef2
...
...
@@ -515,6 +515,9 @@ class MemoryViewSliceType(PyrexType):
def
specialization_suffix
(
self
):
return
"%s_%s"
%
(
self
.
axes_to_name
(),
self
.
dtype_name
)
def
can_coerce_to_pyobject
(
self
,
env
):
return
True
#def global_init_code(self, entry, code):
# code.putln("%s.data = NULL;" % entry.cname)
# code.putln("%s.memview = NULL;" % entry.cname)
...
...
tests/errors/e_cython_parallel.pyx
View file @
dca00ef2
...
...
@@ -126,6 +126,10 @@ with nogil, parallel.parallel():
for
i
in
parallel
.
prange
(
10
):
pass
cdef
int
[:]
dst
,
src
=
object
()
for
i
in
prange
(
10
,
nogil
=
True
):
dst
=
src
_ERRORS
=
u"""
e_cython_parallel.pyx:3:8: cython.parallel.parallel is not a module
e_cython_parallel.pyx:4:0: No such directive: cython.parallel.something
...
...
@@ -156,4 +160,5 @@ e_cython_parallel.pyx:110:7: local variable 'i' referenced before assignment
e_cython_parallel.pyx:119:17: Cannot read reduction variable in loop body
e_cython_parallel.pyx:121:20: stop argument must be numeric
e_cython_parallel.pyx:121:19: prange() can only be used without the GIL
e_cython_parallel.pyx:131:8: Memoryview slices can only be shared in parallel sections
"""
tests/run/memslice.pyx
View file @
dca00ef2
...
...
@@ -6,6 +6,9 @@ from __future__ import unicode_literals
cimport
cython
from
cython
cimport
view
from
cython.parallel
cimport
prange
print
cython
.
array
import
sys
import
re
...
...
@@ -1366,9 +1369,8 @@ def test_nogil_oob1():
print
e
.
args
[
0
]
try
:
# Enable when the nogil exception propagation fix is merged
#with nogil:
nogil_oob
(
a
)
with
nogil
:
nogil_oob
(
a
)
except
IndexError
,
e
:
print
e
.
args
[
0
]
...
...
@@ -1426,3 +1428,32 @@ def test_convert_slicenode_to_indexnode():
a
=
a
[
2
:
4
]
print
a
[
0
]
@
testcase
@
cython
.
boundscheck
(
False
)
@
cython
.
wraparound
(
False
)
def
test_memslice_prange
(
arg
):
"""
>>> test_memslice_prange(IntMockBuffer("A", range(400), shape=(20, 4, 5)))
acquired A
released A
>>> test_memslice_prange(IntMockBuffer("A", range(200), shape=(100, 2, 1)))
acquired A
released A
"""
cdef
int
[:,
:,
:]
src
,
dst
src
=
arg
dst
=
cython
.
array
((
<
object
>
src
).
shape
,
sizeof
(
int
),
format
=
"i"
)
cdef
int
i
,
j
,
k
for
i
in
prange
(
src
.
shape
[
0
],
nogil
=
True
):
for
j
in
range
(
src
.
shape
[
1
]):
for
k
in
range
(
src
.
shape
[
2
]):
dst
[
i
,
j
,
k
]
=
src
[
i
,
j
,
k
]
for
i
in
range
(
src
.
shape
[
0
]):
for
j
in
range
(
src
.
shape
[
1
]):
for
k
in
range
(
src
.
shape
[
2
]):
assert
src
[
i
,
j
,
k
]
==
dst
[
i
,
j
,
k
],
(
src
[
i
,
j
,
k
]
==
dst
[
i
,
j
,
k
])
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