Changeset 2798


Ignore:
Timestamp:
Dec 23, 2012, 8:13:26 AM (6 years ago)
Author:
cameron
Message:

Alignment block size parameters; use carry 'pack' consistently.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/CCGO_HMCPS.py

    r2795 r2798  
    7777#
    7878# The hierarchical merging carry pack strategy packs carries
    79 # into groups of 2, 4, 8 and 16.   For example, to pack
     79# into packs of 2, 4, 8 and 16.   For example, to pack
    8080# 4 carries c0, c1, c2, and c3 into the 32-bit fields of
    8181# a 128-bit register, the following operations are used.
     
    114114  return ((n + align_base - 1) / align_base) * align_base
    115115
    116 def determine_aligned_block_sizes(pack_size, cis):
     116def determine_aligned_block_sizes(pack_size, cis, max_whiles_per_pack = 1, min_block_size = 1):
    117117  aligned_size = {}
    118118  for i in range(cis.block_count): aligned_size[i] = 0
     
    136136        b_carries += aligned_size[sb]
    137137        op += cis.block_op_count[sb]
    138     # Force whiles to use full blocks; this possibly can be relaxed.
    139     if cis.whileblock[b] or b_carries > pack_size:
    140       aligned_size[b] = align(b_carries, pack_size)
     138    #
     139    # Align to min block size
     140    aligned_size[b] = align(b_carries, min_block_size)
     141    # Force whiles to use full packs; this possibly can be relaxed.
     142    if cis.whileblock[b]:
     143      aligned_size[b] = align(aligned_size[b], pack_size/max_whiles_per_pack)
     144    if aligned_size[b] > pack_size:
     145      aligned_size[b] = align(aligned_size[b], pack_size)
    141146    else:
    142       aligned_size[b] = pow2ceil(b_carries)
     147      aligned_size[b] = pow2ceil(aligned_size[b])
    143148  return aligned_size
    144149 
     
    169174 
    170175class HMCPS_CCGO(CCGO.CCGO):
    171     def __init__(self, fw, carryInfoSet, carryGroupVarName='carryG', temp_prefix='__c'):
     176    def __init__(self, fw, carryInfoSet, carryPackVarName='carryG', temp_prefix='__c'):
    172177        self.fw = fw
    173178        self.field_count = 128/fw
    174179        self.carryInfoSet = carryInfoSet
    175         self.carryGroupVar = carryGroupVarName
     180        self.carryPackVar = carryPackVarName
    176181        self.temp_prefix = temp_prefix
    177182        self.aligned_size = determine_aligned_block_sizes(self.field_count, carryInfoSet)
    178         self.carryblock_count = (self.aligned_size[0] + self.field_count - 1) / self.field_count
    179         self.totalblock_count = self.carryblock_count + carryInfoSet.adv_n_count
     183        self.carryPack_count = (self.aligned_size[0] + self.field_count - 1) / self.field_count
     184        self.totalPack_count = self.carryPack_count + carryInfoSet.adv_n_count
    180185        self.alloc_map = {}
    181186        self.alloc_map[0] = 0
     
    184189        self.allocate_ops()
    185190        # carry_offset is used within the inner body of while loops to access local carries.
    186         # The calculated (ub, rp) value is reduced by this amount for the local carry group(s).
     191        # The calculated (ub, rp) value is reduced by this amount for the local carry Pack(s).
    187192        self.carry_offset = 0
    188193#
     
    205210#     
    206211#  while test similar
    207 #    local while decl: use a copy of carryGroup
     212#    local while decl: use a copy of carryPack
    208213#    while finalize  carry combine:   round up and |= into structure
    209214#
    210215    def carry_pack_full(self, ub, v = None, mode = ast.Load()):
    211        if v == None: v = self.carryGroupVar
     216       if v == None: v = self.carryPackVar
    212217       return make_att(make_index(v, ub), '_128', mode)
    213218
    214219    def carry_pack_index(self, fw, ub, rp, mode = ast.Load()):
    215        return make_index(make_att(make_index(self.carryGroupVar, ub), '_%i' % fw), rp, mode)
     220       return make_index(make_att(make_index(self.carryPackVar, ub), '_%i' % fw), rp, mode)
    216221
    217222    def local_pack_full(self, ub, mode = ast.Load()):
    218        return self.carry_pack_full(ub, "sub" + self.carryGroupVar, mode)
     223       return self.carry_pack_full(ub, "sub" + self.carryPackVar, mode)
    219224
    220225
     
    317322     
    318323    def GenerateCarryDecls(self):
    319         return "  ubitblock %s [%i];\n" % (self.carryGroupVar, self.totalblock_count)
     324        return "  ubitblock %s [%i];\n" % (self.carryPackVar, self.totalPack_count)
    320325    def GenerateInitializations(self):
    321         v = self.carryGroupVar       
     326        v = self.carryPackVar       
    322327        inits = ""
    323         for i in range(0, self.totalblock_count):
     328        for i in range(0, self.totalPack_count):
    324329          inits += "%s[%i]._128 = simd<%i>::constant<0>();\n" % (v, i, self.fw)
    325330        for op_no in range(self.carryInfoSet.block_op_count[0]):
     
    328333            ub = posn/self.field_count
    329334            rp = posn%self.field_count
    330             inits += "%s[%i]._%i[%i] = 1;\n" % (self.carryGroupVar, ub, self.fw, rp)
     335            inits += "%s[%i]._%i[%i] = 1;\n" % (self.carryPackVar, ub, self.fw, rp)
    331336        return inits
    332337    def GenerateStreamFunctionDecls(self):
     
    369374        return assigs
    370375    def GenerateAdvanceInAccess(self, operation_no):
    371         return self.carry_pack_full(self.carryblock_count + self.adv_n_map[operation_no])
     376        return self.carry_pack_full(self.carryPack_count + self.adv_n_map[operation_no])
    372377    def GenerateAdvanceOutStore(self, operation_no, adv_out_expr):
    373         return [ast.Assign([self.carry_pack_full(self.carryblock_count + self.adv_n_map[operation_no], mode=ast.Store())],
     378        return [ast.Assign([self.carry_pack_full(self.carryPack_count + self.adv_n_map[operation_no], mode=ast.Store())],
    374379                           make_call("bitblock::srli<64>", [adv_out_expr]))]
    375380    def GenerateTestAll(self, instance_name):
    376         if self.totalblock_count == 0: return ast.Num(0)
     381        if self.totalPack_count == 0: return ast.Num(0)
    377382        else:
    378             v = make_att(instance_name, self.carryGroupVar)
     383            v = make_att(instance_name, self.carryPackVar)
    379384            t = self.carry_pack_full(0, v)
    380             for i in range(1, self.totalblock_count):
     385            for i in range(1, self.totalPack_count):
    381386              t2 = self.carry_pack_full(i, v)
    382387              t = make_call('simd_or', [t, t2])
     
    427432        if count >= self.field_count:
    428433          ub_count = count / self.field_count
    429           decls = [make_callStmt('ubitblock_declare', [mk_var('sub' + self.carryGroupVar), ast.Num(ub_count)])]
     434          decls = [make_callStmt('ubitblock_declare', [mk_var('sub' + self.carryPackVar), ast.Num(ub_count)])]
    430435          count = self.field_count
    431436        else: decls = []
     
    445450
    446451    def EnterLocalWhileBlock(self, operation_offset): 
    447         self.carryGroupVar = "sub" + self.carryGroupVar
     452        self.carryPackVar = "sub" + self.carryPackVar
    448453        self.temp_prefix = "sub" + self.temp_prefix
    449454        self.carry_offset = self.alloc_map[operation_offset]
    450455        #print "self.carry_offset = %i" % self.carry_offset
    451456    def ExitLocalWhileBlock(self): 
    452         self.carryGroupVar = self.carryGroupVar[3:]
     457        self.carryPackVar = self.carryPackVar[3:]
    453458        self.temp_prefix = self.temp_prefix[3:]
    454459        self.carry_offset = 0
     
    495500
    496501    def carry_pack_full(self, ub, v = None, mode = ast.Load()):
    497        if v == None: v = self.carryGroupVar
     502       if v == None: v = self.carryPackVar
    498503       return make_index(v, ub, mode)
    499504
     
    502507
    503508    def GenerateCarryDecls(self):
    504         return "  BitBlock %s [%i];\n" % (self.carryGroupVar, self.totalblock_count)
     509        return "  BitBlock %s [%i];\n" % (self.carryPackVar, self.totalPack_count)
    505510
    506511    def GenerateInitializations(self):
    507         v = self.carryGroupVar       
     512        v = self.carryPackVar       
    508513        inits = ""
    509         for i in range(0, self.totalblock_count):
     514        for i in range(0, self.totalPack_count):
    510515          inits += "%s[%i] = simd<%i>::constant<0>();\n" % (v, i, self.fw)
    511516        for op_no in range(self.carryInfoSet.block_op_count[0]):
     
    514519            ub = posn/self.field_count
    515520            rp = posn%self.field_count
    516             v = "%s[%i]" % (self.carryGroupVar, ub)
     521            v = "%s[%i]" % (self.carryPackVar, ub)
    517522            inits += "%s = simd_or(%s, mvmd<%i>::slli<%i>(simd_const_1)) ;\n" % (v, v, self.fw, rp)
    518523        return inits
    519 
    520     def GenerateCarryInAccess(self, operation_no):
    521         block_no = self.carryInfoSet.containing_block[operation_no]
    522         posn = self.alloc_map[operation_no] - self.carry_offset
    523         ub = posn/self.field_count
    524         rp = posn%self.field_count
    525         #return make_call("convert", [self.carry_pack_index(self.fw, ub, rp)])
    526         if rp == 0: e = self.carry_pack_full(ub)
    527         else: e = make_call("mvmd<%i>::srli<%i>" %(self.fw, rp), [self.carry_pack_full(ub)])
    528         if rp == self.field_count - 1:
    529           return e
    530         else: return make_call('simd_and', [e, mk_var("simd_const_1")])
    531524
    532525    def GenerateLocalDeclare(self, block_no):
     
    549542        #return BitBlock_decls_from_vars(decls)
    550543        return decls + [make_callStmt('BitBlock_declare', [mk_var(t)]) for t in temps]
    551    
    552 class HMCPS_CCGO3(HMCPS_CCGO):
    553 
    554 
    555     def GenerateCarryInAccess(self, operation_no):
    556         block_no = self.carryInfoSet.containing_block[operation_no]
    557         posn = self.alloc_map[operation_no] - self.carry_offset
    558         ub = posn/self.field_count
    559         rp = posn%self.field_count
    560         #return make_call("convert", [self.carry_pack_index(self.fw, ub, rp)])
    561         if rp == 0: e = self.carry_pack_full(ub)
    562         else: e = make_call("mvmd<%i>::srli<%i>" %(self.fw, rp), [self.carry_pack_full(ub)])
    563         if rp == self.field_count - 1:
    564           return e
    565         else: return make_call('simd_and', [e, mk_var("simd_const_1")])
    566 
    567 
     544
Note: See TracChangeset for help on using the changeset viewer.