Rapsodia (generator)
 All Classes Namespaces Files Functions Variables Pages
genOpExp.py
Go to the documentation of this file.
1 ##########################################################
2 # This file is part of Rapsodia released under the LGPL. #
3 # The full COPYRIGHT notice can be found in the top #
4 # level directory of the Rapsodia distribution #
5 ##########################################################
6 import Common.names as names
7 import Common.parameters as parameters
8 import Common.util as util
9 
10 def genExp(sourceList,helper):
11  # the generic bits for exp
12  sourceList.append(generateExpBody(helper))
13  # the exp intrinsic
14  sourceList.append(helper.generateUnaryOp('exp',
15  None,
16  ['s','t'],
17  []))
18 
19 import Common.ast as ast
20 import Common.slice as slice
21 
22 def generateExpBody(helper):
23  aSourceNode=ast.SimpleSource(names.Fixed.pN+'exp', helper.p.iE)
24 
25 # sRet = 's'
26 # rRet = 'r'
27  sRet = util.getVarGlobalName('s')
28  rRet = util.getVarGlobalName('r')
29 
30  if not parameters.useQueue:
31  # compute exp
32  aRHS=ast.FuncCall('exp',[util.vOf('a')])
33  aSourceNode.appendChild(ast.Assignment(util.vOf('r'),aRHS))
34 
35  if parameters.openmpUseOrphaning:
36  aSourceNode.appendChild(ast.Assignment(util.vOf(rRet), util.vOf('r')))
37 
38  s = slice.Slice(aSourceNode)
39  for direct in range(1,parameters.sliceSize+1,1):
40  s.appendChild(ast.Comment('scale input'))
41  for deg in range(1,parameters.o+1,1):
42  aRHS=ast.Multiplication(ast.Constant(str(deg)),util.dOf('a',direct,deg))
43  s.appendChild(ast.Assignment(util.dOf(sRet,direct,deg),aRHS))
44  s.appendChild(ast.Comment('compute output'))
45  for deg in range(1,parameters.o+1,1):
46  # 't' is the convolution result
47  s.appendChild(ast.Assignment(util.dOf('t',direct,deg),
48  helper.generateConvolution((rRet,0,deg-1),
49  (sRet,1,deg),
50  direct,'plus')))
51  # scale the result
52  aRHS=ast.Division(util.dOf('t',direct,deg),ast.Constant(str(deg)+'.0'))
53  s.appendChild(ast.Assignment(util.dOf(rRet,direct,deg),aRHS))
54 # s.endSlice()
55  s.endSliceAndSave()
56  return aSourceNode
57 
58 
59 def genExpReverse(sourceList,helper):
60  sourceList.append(helper.generateUnaryIntrinsicReverse('exp',None,names.Fixed.pN+'exp',None,'r',None,[],[],[],[],getStatementA))
61 
62 
63 def getStatementA(helper,aSource,name,k,resultTypes):
64  operand=util.vOf('a')
65  aLHS=util.vOf('r')
66  aRHS=ast.FuncCall('exp',[operand])
67  da=ast.FuncCall('exp',[operand])
68  aSource.appendChild(ast.Assignment(aLHS,aRHS))
69  aSource.appendChild(helper.generatePushUnaryLocal(da,k,resultTypes,'r','a'))
70  return aSource
71 
72 
73 
74