source: soft/giet_vm/applications/gameoflife/gameoflife.py @ 708

Last change on this file since 708 was 708, checked in by alain, 9 years ago

Adapt the following application to the POSIX threads API

  • convol
  • classif
  • raycast
  • coproc
  • display
  • gameoflife
  • transpose
  • shell
  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/usr/bin/env python
2
3from mapping import *
4
5##################################################################################
6#   file   : gameoflife.py 
7#   date   : february 2015
8#   author : Alain Greiner
9##################################################################################
10#  This file describes the mapping of the multi-threaded "gameoflife"
11#  application on a multi-clusters, multi-processors architecture.
12#  There is one thread per processor.
13#  The mapping of virtual segments is the following:
14#    - There is one shared data vseg in cluster[0][0]
15#    - The code vsegs are replicated on all clusters containing processors.
16#    - The stack vsegs are distributed on all clusters containing processors.
17#    - The heap vsegs are distributed on all clusters containing processors.
18#  This mapping uses 5 platform parameters, (obtained from the "mapping" argument)
19#    - x_size    : number of clusters in a row
20#    - y_size    : number of clusters in a column
21#    - x_width   : number of bits coding x coordinate
22#    - y_width   : number of bits coding y coordinate
23#    - nprocs    : number of processors per cluster
24##################################################################################
25
26######################
27def extend( mapping ):
28
29    x_size    = mapping.x_size
30    y_size    = mapping.y_size
31    nprocs    = mapping.nprocs
32    x_width   = mapping.x_width
33    y_width   = mapping.y_width
34
35    # define vsegs base & size
36    code_base  = 0x10000000
37    code_size  = 0x00010000     # 64 Kbytes (replicated in each cluster)
38   
39    data_base  = 0x20000000
40    data_size  = 0x00200000     # 2 Mbytes (non replicated)
41
42    heap_base  = 0x30000000
43    heap_size  = 0x00040000     # 256 Kbytes (per cluster)     
44
45    stack_base = 0x40000000 
46    stack_size = 0x00200000     # 2 Mbytes (per cluster)
47
48    # create vspace
49    vspace = mapping.addVspace( name = 'gameoflife', startname = 'gol_data', active = False )
50   
51    # data vseg : shared (only in cluster[0,0])
52    mapping.addVseg( vspace, 'gol_data', data_base , data_size, 
53                     'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', 
54                     binpath = 'bin/gameoflife/appli.elf',
55                     local = False , big = True )
56
57    # heap vsegs : shared (one per cluster)
58    for x in xrange (x_size):
59        for y in xrange (y_size):
60            cluster_id = (x * y_size) + y
61            if ( mapping.clusters[cluster_id].procs ):
62                size  = heap_size
63                base  = heap_base + (cluster_id * size)
64
65                mapping.addVseg( vspace, 'gol_heap_%d_%d' %(x,y), base , size, 
66                                 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', 
67                                 local = False )
68
69    # code vsegs : local (one copy in each cluster)
70    for x in xrange (x_size):
71        for y in xrange (y_size):
72            cluster_id = (x * y_size) + y
73            if ( mapping.clusters[cluster_id].procs ):
74
75                mapping.addVseg( vspace, 'gol_code_%d_%d' %(x,y), 
76                                 code_base , code_size,
77                                 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', 
78                                 binpath = 'bin/gameoflife/appli.elf',
79                                 local = True )
80
81    # stacks vsegs: local (one stack per processor => nprocs stacks per cluster)
82    for x in xrange (x_size):
83        for y in xrange (y_size):
84            cluster_id = (x * y_size) + y
85            if ( mapping.clusters[cluster_id].procs ):
86                for p in xrange( nprocs ):
87                    proc_id = (((x * y_size) + y) * nprocs) + p
88                    size    = (stack_size / nprocs) & 0xFFFFF000
89                    base    = stack_base + (proc_id * size)
90
91                    mapping.addVseg( vspace, 'gol_stack_%d_%d_%d' % (x,y,p), 
92                                     base, size, 'C_WU', vtype = 'BUFFER', 
93                                     x = x , y = y , pseg = 'RAM',
94                                     local = True, big = True )
95
96    # distributed tasks / one task per processor
97    for x in xrange (x_size):
98        for y in xrange (y_size):
99            cluster_id = (x * y_size) + y
100            if ( mapping.clusters[cluster_id].procs ):
101                for p in xrange( nprocs ):
102                    if (x == 0) and (y == 0) and (p == 0) :   # main thread
103                        startid = 1
104                        is_main = True
105                    else :                                    # other threads
106                        startid = 0
107                        is_main = False
108
109                    mapping.addThread( vspace,
110                                       'gol_%d_%d_%d' % (x,y,p),
111                                       is_main,
112                                       x, y, p,
113                                       'gol_stack_%d_%d_%d' % (x,y,p),
114                                       'gol_heap_%d_%d' % (x,y),
115                                       startid )
116
117    # extend mapping name
118    mapping.name += '_gol'
119
120    return vspace  # useful for test
121           
122################################ test ##################################################
123
124if __name__ == '__main__':
125
126    vspace = extend( Mapping( 'test', 2, 2, 4 ) )
127    print vspace.xml()
128
129
130# Local Variables:
131# tab-width: 4;
132# c-basic-offset: 4;
133# c-file-offsets:((innamespace . 0)(inline-open . 0));
134# indent-tabs-mode: nil;
135# End:
136#
137# vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
138
Note: See TracBrowser for help on using the repository browser.