<s> DSIZE = <NUM_LIT:4> <EOL> SIZE = <NUM_LIT> <EOL> a_offset = <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> <EOL> b_offset = <NUM_LIT:2> * <NUM_LIT> * <NUM_LIT> <EOL> iochannel = CoramIoChannel ( idx = <NUM_LIT:0> , datawidth = <NUM_LIT:32> ) <EOL> mem0 = CoramMemory ( idx = <NUM_LIT:0> , datawidth = <NUM_LIT:8> * DSIZE , size = SIZE ) <EOL> mem1 = CoramMemory ( idx = <NUM_LIT:1> , datawidth = <NUM_LIT:8> * DSIZE , size = SIZE ) <EOL> mem2 = CoramMemory ( idx = <NUM_LIT:2> , datawidth = <NUM_LIT:8> * DSIZE , size = SIZE ) <EOL> mem3 = CoramMemory ( idx = <NUM_LIT:3> , datawidth = <NUM_LIT:8> * DSIZE , size = SIZE ) <EOL> mem_d0 = CoramMemory ( idx = <NUM_LIT:4> , datawidth = <NUM_LIT:8> * DSIZE , size = SIZE ) <EOL> mem_d1 = CoramMemory ( idx = <NUM_LIT:5> , datawidth = <NUM_LIT:8> * DSIZE , size = SIZE ) <EOL> channel = CoramChannel ( idx = <NUM_LIT:0> , datawidth = <NUM_LIT:8> * DSIZE ) <EOL> def st_set_mesh_size ( mesh_size ) : <EOL> channel . write ( mesh_size ) <EOL> def st_step ( mesh_size , read_start , write_start ) : <EOL> read_page = <NUM_LIT:3> <EOL> write_page = <NUM_LIT:0> <EOL> read_addr = read_start <EOL> mem0 . write ( <NUM_LIT:0> , read_addr , mesh_size ) <EOL> read_addr += mesh_size * DSIZE <EOL> mem1 . write ( <NUM_LIT:0> , read_addr , mesh_size ) <EOL> read_addr += mesh_size * DSIZE <EOL> mem2 . write ( <NUM_LIT:0> , read_addr , mesh_size ) <EOL> read_addr += mesh_size * DSIZE <EOL> write_addr = write_start + mesh_size * DSIZE + DSIZE <EOL> for i in range ( mesh_size - <NUM_LIT:2> ) : <EOL> hot_spot = <NUM_LIT:1> if i == <NUM_LIT:0> else <NUM_LIT:0> <EOL> pos = ( ( hot_spot << <NUM_LIT:6> ) | <EOL> ( ( <NUM_LIT> << write_page ) << <NUM_LIT:4> ) | <EOL> ( <NUM_LIT> << read_page ) ) <EOL> mem0 . wait ( ) <EOL> mem1 . wait ( ) <EOL> mem2 . wait ( ) <EOL> mem3 . wait ( ) <EOL> channel . write ( pos ) <EOL> if read_page == <NUM_LIT:0> : <EOL> mem0 . write_nonblocking ( <NUM_LIT:0> , read_addr , mesh_size ) <EOL> elif read_page == <NUM_LIT:1> : <EOL> mem1 . write_nonblocking ( <NUM_LIT:0> , read_addr , mesh_size ) <EOL> elif read_page == <NUM_LIT:2> : <EOL> mem2 . write_nonblocking ( <NUM_LIT:0> , read_addr , mesh_size ) <EOL> elif read_page == <NUM_LIT:3> : <EOL> mem3 . write_nonblocking ( <NUM_LIT:0> , read_addr , mesh_size ) <EOL> read_page = <NUM_LIT:0> if read_page == <NUM_LIT:3> else read_page + <NUM_LIT:1> <EOL> read_addr += mesh_size * DSIZE <EOL> channel . read ( ) <EOL> mem_d0 . wait ( ) <EOL> mem_d1 . wait ( ) <EOL> if write_page == <NUM_LIT:0> : <EOL> mem_d0 . read_nonblocking ( <NUM_LIT:1> , write_addr , mesh_size - <NUM_LIT:2> ) <EOL> elif write_page == <NUM_LIT:1> : <EOL> mem_d1 . read_nonblocking ( <NUM_LIT:1> , write_addr , mesh_size - <NUM_LIT:2> ) <EOL> write_addr += mesh_size * DSIZE <EOL> write_page = <NUM_LIT:0> if write_page == <NUM_LIT:1> else write_page + <NUM_LIT:1> <EOL> mem_d0 . wait ( ) <EOL> mem_d1 . wait ( ) <EOL> def st_computation ( num_iter , mesh_size ) : <EOL> for i in range ( num_iter / <NUM_LIT:2> ) : <EOL> st_step ( mesh_size , a_offset , b_offset ) <EOL> st_step ( mesh_size , b_offset , a_offset ) <EOL> def st_sum ( mesh_size ) : <EOL> check_sum = <NUM_LIT:0> <EOL> read_addr = a_offset <EOL> for i in range ( mesh_size ) : <EOL> mem0 . write ( <NUM_LIT:0> , read_addr , mesh_size ) <EOL> init_sum = <NUM_LIT:1> if i == <NUM_LIT:0> else <NUM_LIT:0> <EOL> calc_sum = <NUM_LIT:1> <EOL> pos = ( init_sum << <NUM_LIT:8> ) | ( calc_sum << <NUM_LIT:7> ) <EOL> channel . write ( pos ) <EOL> read_addr += mesh_size * DSIZE <EOL> check_sum = channel . read ( ) <EOL> channel . write ( <NUM_LIT:0> ) <EOL> return check_sum <EOL> def st_main ( ) : <EOL> global a_offset <EOL> global b_offset <EOL> mesh_size = iochannel . read ( ) <EOL> print ( "<STR_LIT>" % mesh_size ) <EOL> num_iter = iochannel . read ( ) <EOL> print ( "<STR_LIT>" % num_iter ) <EOL> a_offset = iochannel . read ( ) <EOL> print ( "<STR_LIT>" % a_offset ) <EOL> b_offset = iochannel . read ( ) <EOL> print ( "<STR_LIT>" % b_offset ) <EOL> print ( "<STR_LIT>" ) <EOL> st_set_mesh_size ( mesh_size ) <EOL> print ( "<STR_LIT>" ) <EOL> st_computation ( num_iter , mesh_size ) <EOL> print ( "<STR_LIT>" ) <EOL> check_sum = st_sum ( mesh_size ) <EOL> iochannel . write ( check_sum ) <EOL> while True : <EOL> st_main ( ) </s>
