• No results found

Abstraction Characterization Templates (ACTs)

In document Deb_unc_0153D_18561.pdf (Page 65-69)

ACTs are standard compliant C++ function templates. As with any C++ template, ACTs use template metaprogramming to generate code at compile-time. However, unlike most C++ template metaprogramming techniques, the code generated by ACTs does not produce an executable. Instead of generating low-level code, such as loops and array accesses, an ACT generates a call to a specially annotated function. The specially annotated functions called from inside ACTs are called DSL intrinsic functions. This design pattern of using ACTs and DSL intrinsic functions allows encoding METAL

Array assignment node [operator=]

quarc kernel dispatch()

Binary expression node

[operator+(b.GSHIFT<1,0>, b.GSHIFT<-1,0>)]

evaluate expr()

apply op() [encapsulate mkernel]

GSHIFT expression node [b.GSHIFT<-1,0>]

evaluate expr()

Mddarray terminal node [b]

access fn(b,-1,0)

GSHIFT expression node [b.GSHIFT<1,0>]

evaluate expr()

Mddarray terminal node [b]

access fn(b,1,0)

Mddarray terminal node [a]

access fn(a,0,0)

Figure 5.2: Binary expression tree for the expression a = b.GSHIFT<1,0>() + b.GSHIFT<-1,0>().

of high-level semantics. There is another advantage of ACTs when compared to using annotations and pragmas in high-level code. DSL intrinsic function calls are invisible to application programmers. No programmer intervention is needed to generate these calls. The complete set of annotations required by QUARC gets generated automatically using template metaprogramming.

Example 5.1.

Every ACT function template represents a node of a METAL parse/expression tree. This example shows the expression tree encoded using ACT function calls for a three-point stencil METAL array expression. Figure 5.2 presents this expression tree. The expression tree is constructed recursively in a bottom-up manner. Each ACT has an evaluation member function that in turn calls the evaluation member function of the child nodes of the ACT. Leaf or terminal nodes end the recursion. Terminals are eithermddarrayaccesses or scalar accesses. This recursive evaluation of ACT nodes, happenslazily.

That is the whole expression tree is evaluated only when the result needs to be computed. In this case, the evaluation starts when the overloaded template assignment operator is instantiated.

Figure 5.2 shows the nested template instantiation hierarchy for the ACT and DSL intrinsic function templates. Everydashed-dottedarrow leads to a DSL intrinsic function call. Solid arrows represent parent-child relationship between nodes. All the function calls that are shown in the figure are DSL intrinsic function calls. Thequarc kernel dispatchcall indicates the start of the RHS sub-tree of expression. Theevalaute_exprcalls annotate the point of evaluation of each ACT expression node. Theapply opcall indicates an elemental operation. The function encapsulates an mkernel function. Finally,access fnindicates the terminalmddarrayaccesses. QOPT recognizes these DSL intrinsic function calls, and can recover the whole expression tree. Section 6.2.2 discusses that process.

Aside from annotating expression tree nodes, DSL intrinsic function calls serve an important secondary purpose. Some DSL intrinsic convey additional information that is useful during code- generation. The apply op calls indirectly help QOPT identify mkernel function calls inside the generated IR. The function body for everyapply opfunction is empty except for a callback to the mkernel. This domain-specific information about the code structure allows QOPT to identify user provided mkernel functions. The arguments to anaccess fncalls stores a complete delinearized view of thatmddarrayaccess. QOPT then parses the function call arguments to recover every delinearized

mddarrayaccess. The information is very useful in performing index calculations, reuse distance analysis, and other important code-generation steps.

5.2.1 Types of ACTs and DSL Intrinsic

METAL uses a relatively small number of DSL intrinsic functions to encode its expression trees into QOPT’s IR. Table 5.1 lists all the DSL intrinsic functions that are used currently. These functions are specially annotated using Clang’s attribute ((annotate("string")))feature. The string value passed to this special macro serves as the key to recognize the functions inside the IR. This way it is ensured that the DSL intrinsic functions are recognizable regardless of their C++ mangled function names. The primary purpose served by each DSL intrinsic function call is to encode a type of METAL expression tree node. Example 5.1 introduced few of them, Table 5.1 describes the rest. Some DSL

DSL intrinsic Expression tree node Arguments

access fn Denotes anmddarrayaccess terminal

node.

Constant offset for the affine access function in each array dimension.

apply op Denotes the call site of an mkernel

function.

N/A

binary expr builder Denotes creation of a binary expression node.

N/A

choose expr builder Denotes creation of a

IF EVEN CHOOSEexpression node.

N/A

drill expr builder Denotes creation of aDRILL

expression node.

N/A

drill op Denotes a drill operation that is

performed on evaluation of aDRILL

expression.

Constant index value for a nestedsdlarray

dimension.

evaluate expr Denotes the evaluation point of a

METAL expression node. It is emitted by all types of METAL expressions.

Constant index value for a nestedsdlarray

dimension.

gshift expr builder Denotes creation of aGSHIFT

expression node.

N/A

gshift expr builder Denotes creation of aGSHIFT

expression node.

N/A

quarc kernel dispatch Denotes the start point for evaluating a METAL expression.

N/A

quarc Rkernel dispatch Denotes the start point for evaluating a METAL reduction expression.

N/A

scalar access fn Denotes a scalar terminal expression node

The actual scalar value encapsulated within the expression node.

scalar expr builder Denotes creation of a scalar expression node.

N/A

sdlarray copy Denotes an assignment expression for

sdlarrayobjects.

N/A

sdlarray subop Denotes an access to ansdlarray

element.

N/A

unary expr builder Denotes creation of a unary expression node

N/A

similar secondary purposes. Nestedsdlarrayaccesses are preserved bysdlarray subop. The argument passed todrill opintrinsic calls convey the index of an indirect access of sdlarray

elements of an mddarray. The first argument to reduction kernel dispatchindicates if a reduction expression is commutative.

In document Deb_unc_0153D_18561.pdf (Page 65-69)