Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
56af5641
Commit
56af5641
authored
8 years ago
by
Jan Hoenig
Browse files
Options
Downloads
Patches
Plain Diff
LLVM-backend generates Object-files, whcih can be imported in C.
parent
39a096fa
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
astnodes.py
+11
-0
11 additions, 0 deletions
astnodes.py
backends/llvm.py
+6
-1
6 additions, 1 deletion
backends/llvm.py
llvm/kernelcreation.py
+2
-2
2 additions, 2 deletions
llvm/kernelcreation.py
transformations.py
+28
-11
28 additions, 11 deletions
transformations.py
types.py
+17
-2
17 additions, 2 deletions
types.py
with
64 additions
and
16 deletions
astnodes.py
+
11
−
0
View file @
56af5641
...
...
@@ -487,6 +487,17 @@ class Indexed(Expr):
return
'
%s[%s]
'
%
(
self
.
args
[
0
],
self
.
args
[
1
])
class
PointerArithmetic
(
Expr
):
def
__init__
(
self
,
args
,
pointer
,
parent
=
None
):
super
(
PointerArithmetic
,
self
).
__init__
([
args
]
+
[
pointer
],
parent
)
self
.
pointer
=
pointer
self
.
offset
=
args
self
.
dtype
=
pointer
.
dtype
def
__repr__
(
self
):
return
'
*(%s + %s)
'
%
(
self
.
pointer
,
self
.
args
)
class
Number
(
Node
,
sp
.
AtomicExpr
):
def
__init__
(
self
,
number
,
parent
=
None
):
super
(
Number
,
self
).
__init__
(
parent
)
...
...
This diff is collapsed.
Click to expand it.
backends/llvm.py
+
6
−
1
View file @
56af5641
...
...
@@ -188,6 +188,11 @@ class LLVMPrinter(Printer):
gep
=
self
.
builder
.
gep
(
ptr
,
[
index
])
return
self
.
builder
.
load
(
gep
,
name
=
indexed
.
base
.
label
.
name
)
def
_print_PointerArithmetic
(
self
,
pointer
):
ptr
=
self
.
_print
(
pointer
.
pointer
)
index
=
self
.
_print
(
pointer
.
offset
)
return
self
.
builder
.
gep
(
ptr
,
[
index
])
# Should have a list of math library functions to validate this.
# TODO function calls
def
_print_Function
(
self
,
expr
):
...
...
@@ -202,4 +207,4 @@ class LLVMPrinter(Printer):
def
emptyPrinter
(
self
,
expr
):
raise
TypeError
(
"
Unsupported type for LLVM JIT conversion: %s %s
"
%
type
(
expr
),
expr
)
%
(
type
(
expr
),
expr
)
)
This diff is collapsed.
Click to expand it.
llvm/kernelcreation.py
+
2
−
2
View file @
56af5641
...
...
@@ -60,9 +60,9 @@ def createKernel(listOfEquations, functionName="kernel", typeForSymbol=None, spl
resolveFieldAccesses
(
code
,
readOnlyFields
,
fieldToBasePointerInfo
=
basePointerInfos
)
moveConstantsBeforeLoop
(
code
)
#
print(code)
print
(
code
)
desympy_ast
(
code
)
#
print(code)
print
(
code
)
insert_casts
(
code
)
return
code
This diff is collapsed.
Click to expand it.
transformations.py
+
28
−
11
View file @
56af5641
...
...
@@ -549,23 +549,38 @@ def insert_casts(node):
:param node: ast which should be traversed
:return: node
"""
def
conversion
(
args
):
target
=
args
[
0
]
if
isinstance
(
target
.
dtype
,
PointerType
):
# Pointer arithmetic
for
arg
in
args
[
1
:]:
# Check validness
if
not
arg
.
dtype
.
is_int
()
and
not
arg
.
dtype
.
is_uint
():
raise
ValueError
(
"
Impossible pointer arithmetic
"
,
target
,
arg
)
pointer
=
ast
.
PointerArithmetic
(
ast
.
Add
(
args
[
1
:]),
target
)
return
[
pointer
]
else
:
for
i
in
range
(
len
(
args
)):
if
args
[
i
].
dtype
!=
target
.
dtype
:
args
[
i
]
=
ast
.
Conversion
(
args
[
i
],
target
.
dtype
,
node
)
return
args
for
arg
in
node
.
args
:
insert_casts
(
arg
)
if
isinstance
(
node
,
ast
.
Indexed
):
#TODO revmove this
pass
elif
isinstance
(
node
,
ast
.
Expr
):
print
(
node
.
args
)
print
([
type
(
arg
)
for
arg
in
node
.
args
])
print
([
arg
.
dtype
for
arg
in
node
.
args
])
#
print(
node,
node.args)
#
print([type(arg) for arg in node.args])
#
print([arg.dtype for arg in node.args])
args
=
sorted
((
arg
for
arg
in
node
.
args
),
key
=
attrgetter
(
'
dtype
'
))
target
=
args
[
0
]
for
i
in
range
(
len
(
args
)):
if
args
[
i
].
dtype
!=
target
.
dtype
:
args
[
i
]
=
ast
.
Conversion
(
args
[
i
],
target
.
dtype
,
node
)
node
.
args
=
args
node
.
args
=
conversion
(
args
)
node
.
dtype
=
target
.
dtype
print
(
node
.
dtype
)
#print(node.dtype)
#print(node)
elif
isinstance
(
node
,
ast
.
SympyAssignment
):
if
node
.
lhs
.
dtype
!=
node
.
rhs
.
dtype
:
node
.
replace
(
node
.
rhs
,
ast
.
Conversion
(
node
.
rhs
,
node
.
lhs
.
dtype
))
...
...
@@ -600,7 +615,8 @@ def desympy_ast(node):
#elif isinstance(arg, sp.containers.Tuple):
#
else
:
print
(
'
Not transforming:
'
,
type
(
arg
),
arg
)
#print('Not transforming:', type(arg), arg)
pass
for
arg
in
node
.
args
:
desympy_ast
(
arg
)
return
node
...
...
@@ -616,8 +632,9 @@ def check_dtype(node):
elif
isinstance
(
node
,
ast
.
SympyAssignment
):
pass
else
:
print
(
node
)
print
(
node
.
dtype
)
#print(node)
#print(node.dtype)
pass
for
arg
in
node
.
args
:
check_dtype
(
arg
)
This diff is collapsed.
Click to expand it.
types.py
+
17
−
2
View file @
56af5641
...
...
@@ -160,12 +160,12 @@ class Type(object):
if
isinstance
(
other
,
BasicType
):
return
self
.
numpyDtype
<
other
.
numpyDtype
# TODO const
if
isinstance
(
other
,
PointerType
):
return
Tru
e
# TODO test
return
Fals
e
# TODO test
if
isinstance
(
other
,
StructType
):
raise
NotImplementedError
(
"
Struct type comparison is not yet implemented
"
)
if
isinstance
(
self
,
PointerType
):
if
isinstance
(
other
,
BasicType
):
return
Fals
e
# TODO test
return
Tru
e
# TODO test
if
isinstance
(
other
,
PointerType
):
return
self
.
baseType
<
other
.
baseType
# TODO const, restrict
if
isinstance
(
other
,
StructType
):
...
...
@@ -207,6 +207,21 @@ class BasicType(Type):
def
numpyDtype
(
self
):
return
self
.
_dtype
def
is_int
(
self
):
return
self
.
numpyDtype
in
np
.
sctypes
[
'
int
'
]
def
is_float
(
self
):
return
self
.
numpyDtype
in
np
.
sctypes
[
'
float
'
]
def
is_uint
(
self
):
return
self
.
numpyDtype
in
np
.
sctypes
[
'
uint
'
]
def
is_comlex
(
self
):
return
self
.
numpyDtype
in
np
.
sctypes
[
'
complex
'
]
def
is_other
(
self
):
return
self
.
numpyDtype
in
np
.
sctypes
[
'
others
'
]
def
__repr__
(
self
):
result
=
BasicType
.
numpyNameToC
(
str
(
self
.
_dtype
))
if
self
.
const
:
...
...
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