Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Strange committed Jul 17, 2019
1 parent 8786cb3 commit f1fa484
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
23 changes: 23 additions & 0 deletions acc/backend/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import acc.frontend.parallel.parallel as parallel
import acc.backend.common as common
import os
import random
import string
# Just needed for type hints
import acc.ir.intrep as intrep

Expand Down Expand Up @@ -73,6 +75,8 @@ def _apply_parallel_node(modified_src: common.CompilerTarget, node: intrep.IrNod
modified_src.add_import("multiprocessing")

## Move the node's source code into a kernel function
signature = _create_signature(intermediate_rep, ["ls, sqrs"]) # TODO: Determine necessary parameters
kernelsrc = signature + os.linesep + node.src
modified_src.add_kernel(kernelsrc)

## Place process creation, data movement, process destruction in the old location
Expand All @@ -82,3 +86,22 @@ def _apply_loop_node(modified_src: common.CompilerTarget, node: intrep.IrNode, i
"""
"""
pass

def _create_signature(intermediate_rep: intrep.IntermediateRepresentation, params: [str]) -> str:
"""
Creates a statistically unique signature of the form `def name_mangled_kernel(args):`
and returns it.
By 'statistically unique', I mean that the name of the function will be generated randomly,
but over such a large space of possible values, that there is a virtual guarantee of
uniqueness. I am too lazy right now to do this better.
"""
# Create name
letters = string.ascii_letters
unique = "".join(random.choices(letters, k=15))

# Put together parameter list
args = ",".join(params)
args = "({})".format(args)

return "def {}_kernel_function{}:".format(unique, args)
9 changes: 5 additions & 4 deletions acc/frontend/loop/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class LoopNode(intrep.IrNode):
"""
Node for the IntermediateRepresentation tree that is used for loop constructs.
"""
def __init__(self, lineno: int):
super().__init__(lineno)
def __init__(self, lineno: int, src: str):
super().__init__(lineno, src)
self.collapse = None # clauses.collapse.CollapseClause
self.gang = None
self.worker = None # clauses.worker.WorkerClause
Expand Down Expand Up @@ -48,7 +48,7 @@ def __str__(self):
s += " reduction {}\n".format(self.reduction)
return s

def loop(clauses, intermediate_rep, lineno, dbg, *args, **kwargs):
def loop(clauses: [str], intermediate_rep: intrep.IntermediateRepresentation, lineno: int, dbg, *args, **kwargs):
"""
From the OpenACC 2.7 standard:
Expand Down Expand Up @@ -108,7 +108,8 @@ def loop(clauses, intermediate_rep, lineno, dbg, *args, **kwargs):
- A loop associated with a loop construct that does not have a seq clause must be written
such that the loop iteration count is computable when entering the loop construct.
"""
loop_node = LoopNode(lineno)
src = intermediate_rep.get_source_region(lineno)
loop_node = LoopNode(lineno, src)
index = 0
while index != -1:
index = apply_clause(index, clauses, intermediate_rep, loop_node, dbg)
Expand Down
5 changes: 3 additions & 2 deletions acc/frontend/parallel/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _apply_clause(index, clause_list, intermediate_rep, parallel_node, dbg):
else:
return commonclauses.apply_clause(*args)

def _loop(index, clause_list, intermediate_rep, parallel_node, dbg):
def _loop(index: int, clause_list: [str], intermediate_rep: intrep.IntermediateRepresentation, parallel_node: ParallelNode, dbg):
"""
A parallel construct can be combined with a loop construct by
the following:
Expand All @@ -207,7 +207,8 @@ def _loop(index, clause_list, intermediate_rep, parallel_node, dbg):
Once we return from this function, the parallel node will get
added to the IR tree, along with its child.
"""
loop_node = loop.LoopNode(parallel_node.lineno)
src = intermediate_rep.get_source_region(parallel_node.lineno)
loop_node = loop.LoopNode(parallel_node.lineno, src)

index = index + 1 if index + 1 < len(clause_list) else -1
if index == -1:
Expand Down
6 changes: 4 additions & 2 deletions acc/ir/intrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"""
import acc.frontend.util.util as util
import acc.frontend.util.errors as errors
import acc.ir.metavars as metavars
import acc.ir.icv as icv
import os
import re

Expand All @@ -32,7 +34,7 @@ def __init__(self, lineno: int, src: str, children=None):
self.children = children

self.lineno = lineno
self.src = None
self.src = src

def add_child(self, child):
"""
Expand Down Expand Up @@ -65,7 +67,7 @@ class IntermediateRepresentation:
# TODO: Give an example
"""
def __init__(self, meta_data, icvs):
def __init__(self, meta_data: metavars.MetaVars, icvs: icv.ICVs):
"""
"""
self.meta_data = meta_data # All the meta data
Expand Down

0 comments on commit f1fa484

Please sign in to comment.