Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tom Harke
pystencils
Commits
12459396
Commit
12459396
authored
Oct 17, 2019
by
Stephan Seitz
Browse files
Fix #15: do not require pycuda for OpenCL execution
parent
a8292b88
Changes
2
Hide whitespace changes
Inline
Side-by-side
pystencils/transformations.py
View file @
12459396
...
...
@@ -1312,13 +1312,16 @@ def implement_interpolations(ast_node: ast.Node,
substitutions
=
{
i
:
to_texture_map
[
i
.
symbol
.
interpolator
].
at
(
[
o
for
o
in
i
.
offsets
])
for
i
in
interpolation_accesses
}
import
pycuda.driver
as
cuda
for
texture
in
substitutions
.
values
():
if
can_use_hw_interpolation
(
texture
):
texture
.
filter_mode
=
cuda
.
filter_mode
.
LINEAR
else
:
texture
.
filter_mode
=
cuda
.
filter_mode
.
POINT
texture
.
read_as_integer
=
True
try
:
import
pycuda.driver
as
cuda
for
texture
in
substitutions
.
values
():
if
can_use_hw_interpolation
(
texture
):
texture
.
filter_mode
=
cuda
.
filter_mode
.
LINEAR
else
:
texture
.
filter_mode
=
cuda
.
filter_mode
.
POINT
texture
.
read_as_integer
=
True
except
Exception
:
pass
if
isinstance
(
ast_node
,
AssignmentCollection
):
ast_node
=
ast_node
.
subs
(
substitutions
)
...
...
pystencils_tests/test_opencl.py
View file @
12459396
import
numpy
as
np
import
pytest
import
sympy
as
sp
import
pystencils
import
sympy
as
sp
from
pystencils.backends.cuda_backend
import
CudaBackend
from
pystencils.backends.opencl_backend
import
OpenClBackend
from
pystencils.opencl.opencljit
import
make_python_function
...
...
@@ -195,5 +195,35 @@ def test_opencl_jit_with_parameter():
assert
np
.
allclose
(
result_cuda
,
result_opencl
)
if
__name__
==
'__main__'
:
test_opencl_jit
()
@
pytest
.
mark
.
skipif
(
not
HAS_OPENCL
,
reason
=
"Test requires pyopencl"
)
def
test_without_cuda
():
z
,
y
,
x
=
pystencils
.
fields
(
"z, y, x: [20,30]"
)
assignments
=
pystencils
.
AssignmentCollection
({
z
[
0
,
0
]:
x
[
0
,
0
]
*
sp
.
log
(
x
[
0
,
0
]
*
y
[
0
,
0
])
})
print
(
assignments
)
ast
=
pystencils
.
create_kernel
(
assignments
,
target
=
'gpu'
)
print
(
ast
)
opencl_code
=
pystencils
.
show_code
(
ast
,
custom_backend
=
OpenClBackend
())
print
(
opencl_code
)
x_cpu
=
np
.
random
.
rand
(
20
,
30
)
y_cpu
=
np
.
random
.
rand
(
20
,
30
)
z_cpu
=
np
.
random
.
rand
(
20
,
30
)
import
pyopencl.array
as
array
ctx
=
cl
.
create_some_context
(
0
)
queue
=
cl
.
CommandQueue
(
ctx
)
x
=
array
.
to_device
(
queue
,
x_cpu
)
y
=
array
.
to_device
(
queue
,
y_cpu
)
z
=
array
.
to_device
(
queue
,
z_cpu
)
opencl_kernel
=
make_python_function
(
ast
,
queue
,
ctx
)
assert
opencl_kernel
is
not
None
opencl_kernel
(
x
=
x
,
y
=
y
,
z
=
z
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment