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
Stephan Seitz
pystencils
Commits
4465a595
Commit
4465a595
authored
Aug 10, 2020
by
Markus Holzer
Browse files
Added test case for vectorisation
parent
cd3a2f3e
Changes
3
Hide whitespace changes
Inline
Side-by-side
pystencils/backends/cbackend.py
View file @
4465a595
...
...
@@ -298,7 +298,7 @@ class CBackend:
return
node
.
get_code
(
self
.
_dialect
,
self
.
_vector_instruction_set
)
def
_print_SourceCodeComment
(
self
,
node
):
return
"/*
"
+
node
.
text
+
"
*/"
return
f
"/*
{
node
.
text
}
*/"
def
_print_EmptyLine
(
self
,
node
):
return
""
...
...
@@ -316,7 +316,7 @@ class CBackend:
result
=
f
"if (
{
condition_expr
}
)
\n
{
true_block
}
"
if
node
.
false_block
:
false_block
=
self
.
_print_Block
(
node
.
false_block
)
result
+=
"else
"
+
false_block
result
+=
f
"else
{
false_block
}
"
return
result
...
...
@@ -336,7 +336,7 @@ class CustomSympyPrinter(CCodePrinter):
return
self
.
_typed_number
(
expr
.
evalf
(),
get_type_of_expression
(
expr
))
if
expr
.
exp
.
is_integer
and
expr
.
exp
.
is_number
and
0
<
expr
.
exp
<
8
:
return
"(
"
+
self
.
_print
(
sp
.
Mul
(
*
[
expr
.
base
]
*
expr
.
exp
,
evaluate
=
False
))
+
"
)"
return
f
"(
{
self
.
_print
(
sp
.
Mul
(
*
[
expr
.
base
]
*
expr
.
exp
,
evaluate
=
False
))
}
)"
elif
expr
.
exp
.
is_integer
and
expr
.
exp
.
is_number
and
-
8
<
expr
.
exp
<
0
:
return
f
"1 / (
{
self
.
_print
(
sp
.
Mul
(
*
([
expr
.
base
]
*
-
expr
.
exp
),
evaluate
=
False
))
}
)"
else
:
...
...
pystencils/backends/cuda_backend.py
View file @
4465a595
...
...
@@ -104,7 +104,6 @@ class CudaSympyPrinter(CustomSympyPrinter):
assert
len
(
expr
.
args
)
==
1
,
f
"__fsqrt_rn has one argument, but
{
len
(
expr
.
args
)
}
where given"
return
f
"__fsqrt_rn(
{
self
.
_print
(
expr
.
args
[
0
])
}
)"
elif
isinstance
(
expr
,
fast_inv_sqrt
):
print
(
len
(
expr
.
args
)
==
1
)
assert
len
(
expr
.
args
)
==
1
,
f
"__frsqrt_rn has one argument, but
{
len
(
expr
.
args
)
}
where given"
return
f
"__frsqrt_rn(
{
self
.
_print
(
expr
.
args
[
0
])
}
)"
return
super
().
_print_Function
(
expr
)
pystencils_tests/test_fast_approximation.py
View file @
4465a595
...
...
@@ -11,9 +11,9 @@ def test_fast_sqrt():
assert
len
(
insert_fast_sqrts
(
expr
).
atoms
(
fast_sqrt
))
==
1
assert
len
(
insert_fast_sqrts
([
expr
])[
0
].
atoms
(
fast_sqrt
))
==
1
ast
=
ps
.
create_kernel
(
ps
.
Assignment
(
g
[
0
,
0
],
insert_fast_sqrts
(
expr
)),
target
=
'gpu'
)
ast
.
compile
()
code_str
=
ps
.
get_code_str
(
ast
)
ast
_gpu
=
ps
.
create_kernel
(
ps
.
Assignment
(
g
[
0
,
0
],
insert_fast_sqrts
(
expr
)),
target
=
'gpu'
)
ast
_gpu
.
compile
()
code_str
=
ps
.
get_code_str
(
ast
_gpu
)
assert
'__fsqrt_rn'
in
code_str
expr
=
ps
.
Assignment
(
sp
.
Symbol
(
"tmp"
),
3
/
sp
.
sqrt
(
f
[
0
,
0
]
+
f
[
1
,
0
]))
...
...
@@ -21,9 +21,9 @@ def test_fast_sqrt():
ac
=
ps
.
AssignmentCollection
([
expr
],
[])
assert
len
(
insert_fast_sqrts
(
ac
).
main_assignments
[
0
].
atoms
(
fast_inv_sqrt
))
==
1
ast
=
ps
.
create_kernel
(
insert_fast_sqrts
(
ac
),
target
=
'gpu'
)
ast
.
compile
()
code_str
=
ps
.
get_code_str
(
ast
)
ast
_gpu
=
ps
.
create_kernel
(
insert_fast_sqrts
(
ac
),
target
=
'gpu'
)
ast
_gpu
.
compile
()
code_str
=
ps
.
get_code_str
(
ast
_gpu
)
assert
'__frsqrt_rn'
in
code_str
...
...
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