[457] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | from mapping import * |
---|
| 4 | |
---|
| 5 | ###################################################################################### |
---|
| 6 | # file : classif.py |
---|
| 7 | # date : november 2014 |
---|
| 8 | # author : Alain Greiner |
---|
| 9 | ####################################################################################### |
---|
| 10 | # This file describes the mapping of the multi-threaded "classif" |
---|
| 11 | # application on a multi-clusters, multi-processors architecture. |
---|
| 12 | # The mapping of tasks on processors is the following: |
---|
| 13 | # - one "load" task per cluster, |
---|
| 14 | # - (nprocs-1) "analyse" task per cluster. |
---|
| 15 | # The mapping of virtual segments on the clusters is the following: |
---|
| 16 | # - The code vsegs are replicated on all clusters. |
---|
| 17 | # - There is one shared data vseg per cluster. |
---|
| 18 | # - The stacks vsegs are distibuted on all clusters. |
---|
| 19 | # This mapping uses 5 platform parameters, (obtained from the "mapping" argument) |
---|
| 20 | # - x_size : number of clusters in a row |
---|
| 21 | # - y_size : number of clusters in a column |
---|
| 22 | # - x_width : number of bits for x field |
---|
| 23 | # - y_width : number of bits for y field |
---|
| 24 | # - nprocs : number of processors per cluster |
---|
| 25 | # |
---|
| 26 | # WARNING: The target architecture cannot contain more than (4*4) clusters |
---|
| 27 | # and must contain at least 2 processors per cluster. |
---|
| 28 | #################################################################################### |
---|
| 29 | |
---|
| 30 | ######################### |
---|
| 31 | def classif( mapping ): |
---|
| 32 | |
---|
| 33 | x_size = mapping.x_size |
---|
| 34 | y_size = mapping.y_size |
---|
| 35 | nprocs = mapping.nprocs |
---|
| 36 | x_width = mapping.x_width |
---|
| 37 | y_width = mapping.y_width |
---|
| 38 | |
---|
| 39 | assert (x_size <= 4) and (y_size <= 4) |
---|
| 40 | assert (nprocs >= 2) |
---|
| 41 | |
---|
| 42 | # define vsegs base & size |
---|
| 43 | code_base = 0x10000000 |
---|
| 44 | code_size = 0x00010000 # 64 Kbytes (replicated in each cluster) |
---|
| 45 | |
---|
| 46 | data_base = 0x20000000 |
---|
| 47 | data_size = 0x00010000 # 64 Kbytes (per cluster) |
---|
| 48 | |
---|
| 49 | stack_base = 0x40000000 |
---|
| 50 | stack_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
| 51 | |
---|
| 52 | # create vspace |
---|
| 53 | vspace = mapping.addVspace( name = 'classif', startname = 'classif_data_0_0' ) |
---|
| 54 | |
---|
| 55 | # data_x_y vsegs : shared / one per cluster |
---|
| 56 | for x in xrange (x_size): |
---|
| 57 | for y in xrange (y_size): |
---|
| 58 | base = data_base + ( (4*x + y) * data_size ) |
---|
| 59 | |
---|
| 60 | mapping.addVseg( vspace, 'classif_data_%d_%d' %(x,y), base , data_size, |
---|
| 61 | 'C_WU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
| 62 | binpath = 'build/classif/classif.elf', |
---|
| 63 | local = False ) |
---|
| 64 | |
---|
| 65 | # code vsegs : local (one copy in each cluster) |
---|
| 66 | for x in xrange (x_size): |
---|
| 67 | for y in xrange (y_size): |
---|
| 68 | |
---|
| 69 | mapping.addVseg( vspace, 'classif_code_%d_%d' %(x,y), code_base , code_size, |
---|
| 70 | 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
| 71 | binpath = 'build/classif/classif.elf', |
---|
| 72 | local = True ) |
---|
| 73 | |
---|
| 74 | # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) |
---|
| 75 | for x in xrange (x_size): |
---|
| 76 | for y in xrange (y_size): |
---|
| 77 | for p in xrange( nprocs ): |
---|
| 78 | proc_id = (((x * y_size) + y) * nprocs) + p |
---|
| 79 | size = (stack_size / nprocs) & 0xFFFFF000 |
---|
| 80 | base = stack_base + (proc_id * size) |
---|
| 81 | |
---|
| 82 | mapping.addVseg( vspace, 'classif_stack_%d_%d_%d' % (x,y,p), base, size, |
---|
| 83 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
| 84 | local = True, big = True ) |
---|
| 85 | |
---|
| 86 | # distributed tasks / one task per processor |
---|
| 87 | for x in xrange (x_size): |
---|
| 88 | for y in xrange (y_size): |
---|
| 89 | for p in xrange( nprocs ): |
---|
| 90 | trdid = (((x * y_size) + y) * nprocs) + p |
---|
| 91 | if ( p== 0 ): # task load |
---|
| 92 | task_index = 0 |
---|
| 93 | task_name = 'load_%d_%d_%d' %(x,y,p) |
---|
| 94 | else : # task analyse |
---|
| 95 | task_index = 1 |
---|
| 96 | task_name = 'analyse_%d_%d_%d' % (x,y,p |
---|
| 97 | ) |
---|
| 98 | mapping.addTask( vspace, task_name, trdid, x, y, p, |
---|
| 99 | 'classif_stack_%d_%d_%d' % (x,y,p), '' , task_index ) |
---|
| 100 | |
---|
| 101 | # extend mapping name |
---|
| 102 | mapping.name += '_classif' |
---|
| 103 | |
---|
| 104 | return vspace # useful for test |
---|
| 105 | |
---|
| 106 | ################################ test ###################################################### |
---|
| 107 | |
---|
| 108 | if __name__ == '__main__': |
---|
| 109 | |
---|
| 110 | vspace = classif( Mapping( 'test', 2, 2, 4 ) ) |
---|
| 111 | print vspace.xml() |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | # Local Variables: |
---|
| 115 | # tab-width: 4; |
---|
| 116 | # c-basic-offset: 4; |
---|
| 117 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 118 | # indent-tabs-mode: nil; |
---|
| 119 | # End: |
---|
| 120 | # |
---|
| 121 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 122 | |
---|