source: PROJECT_CORE_MPI/MPI_HCL/TRUNK/HT_4.vhd @ 96

Last change on this file since 96 was 96, checked in by rolagamo, 10 years ago
File size: 16.4 KB
Line 
1----------------------------------------------------------------------------------
2-- Company:
3-- Engineer:
4--
5-- Create Date:    12:04:21 04/22/2013
6-- Design Name:
7-- Module Name:    HT_process - Behavioral
8-- Project Name:
9-- Target Devices:
10-- Tool versions:
11-- Description:
12--
13-- Dependencies:
14--
15-- Revision:
16-- Revision 0.01 - File Created
17-- Additional Comments:
18--
19----------------------------------------------------------------------------------
20library IEEE;
21use IEEE.STD_LOGIC_1164.ALL;
22USE ieee.numeric_std.ALL;
23library NocLib ;
24use std.textio.all;
25use NocLib.CoreTypes.all;
26use work.Packet_type.all;
27use work.MPI_RMA.all;
28-- Uncomment the following library declaration if using
29-- arithmetic functions with Signed or Unsigned values
30--use IEEE.NUMERIC_STD.ALL;
31
32-- Uncomment the following library declaration if instantiating
33-- any Xilinx primitives in this code.
34--library UNISIM;
35--use UNISIM.VComponents.all;
36
37--entity HT_process is
38--              generic (Task_id : natural:=0);
39--    Port ( clk : in  STD_LOGIC;
40--           reset : in  STD_LOGIC;
41--                        en : in std_logic; -- active la tâche
42--           Interf_i : in  core_i; --signaux pour l'interface IO
43--                        Interf_o : out  core_o; --signaux pour l'interface IO
44--           mem_o : out typ_dpram_o; -- signaux pour l'accès à la mémoire
45--                        mem_i : in typ_dpram_i -- signaux pour l'accès à la mémoire
46--                        );
47--end HT_process;
48
49architecture A2 of HT_process is
50
51  type typ_mae is (start,Fillmem,NextFill,InitApp,GetRank,WInCreate,WinPost,WinStart,
52  putdata,getdata,WinWait,WinCompleted,MpiSpawn,finalize,st_timeout);
53        signal sram : typ_dpram;
54        signal MyGroup:mpi_group;
55        signal MyWin : mpi_win;
56        signal MyRank :std_logic_vector(3 downto 0);
57        signal intercomm,array_of_errcodes : natural;
58        signal ct_state:natural:=0;
59signal Libr : Core_io;  --regroupe tous les signaux IO de la bibliothèque
60signal RunState : typ_mae;
61
62begin
63
64--MAE du PE
65--=======================================================================
66-- Interf<=Libr;
67
68
69 pPutGet:process(clk,reset,en)
70 
71        constant DATAPTR : natural :=256;
72        variable nb_rma:natural range 0 to 15:=0;
73        variable bfill,destrank,pid,mport : natural range 0 to 15;
74        variable fsrc,ret : natural range 0 to 15:=0;
75        variable timeout,ct,dlen,dcount : natural range 0 to 255;
76        variable adrToset,SrcAdr,DestAdr : std_logic_vector(ADRLEN-1 downto 0);
77        variable mywin : Mpi_win;
78        variable command , argv , maxprocs , info , root : natural:=0; --variable pour le spawn
79        variable comm : natural :=0; 
80        variable Spawn_on: std_logic:='0';
81        variable  adresse,adresse_rd :natural range 0 to 65536;
82        variable status_reg,config_reg :std_logic_vector(Word-1 downto 0):=(others=>'0');
83
84        --=======================================================
85        --variables pour la création du fichier de résultats
86                -- synthesis translate_off
87                type char_file is file of character;
88        file f: text;
89        variable status :file_open_status ;
90        variable char_count: integer range 0 to 65536 := 0;
91                  variable str: string (1 to 79) ;
92                  variable L: line; 
93                  variable fopened: std_logic:='0';
94                 
95                  constant simres : time :=1 ps; --simulation resolution
96                  constant realres : real :=1.0e-3; --ramener le temps en ns
97                  -- returns real value of time parameter using pure VHDL
98             function rt(t : time) return real is
99               begin
100                        return real(t/simres) * realres;
101             end;
102                 -- synthesis translate_on
103--======================================================
104        begin
105        --=== Partie combinatoire du process ===================================
106                       
107        --=== Fin de la partie combinatoire du process ==========================       
108               
109                   
110           
111        --end loop;
112       
113        if (clk'event and clk='1') and en='1' then 
114                       
115                       
116                if reset='1' then
117                                        RunState<=start;
118                                       
119                else
120                        --==========================================================
121                        --affectation des entrées sorties mémoires
122                        sram.i.data_out<=mem_I.data_out;
123                        mem_o.addr_wr<=sram.O.addr_wr;
124                        mem_o.addr_rd<=sram.O.addr_rd ; 
125                        mem_o.we<=sram.O.we;
126                        mem_o.ena<=sram.O.ena;
127                        mem_o.enb<=sram.O.enb;
128                        mem_o.data_in<=sram.O.data_in;
129                        --affectation des entrées sorties MPI_HCL
130                        Interf_o.Instr_EN<=Libr.O.instr_en;
131                        Interf_o.Membusy<=Libr.O.MemBusy;
132                        Interf_o.Instruction<=Libr.O.Instruction;
133                        Libr.i.Instr_ack<=Interf_i.Instr_ack;
134                        Libr.i.InitOk<=Interf_i.InitOk;
135                        Libr.i.Hold_Req<=Interf_i.Hold_req;
136                        Libr.I.Spawned<=Interf_i.Spawned;
137                        --Libr.i.Hold_Ack<=Interf_i.Hold_Ack;
138                        Libr.i.RamSel<=Interf_i.RamSel;
139                        --ct_state<=ct; --pour débogage
140                        --============================================================
141                       
142                        case  RunState is
143                        when start =>
144                                --Dcount<=0;
145                                if bfill=0 then -- si le nombre de bloc de mémoire remplis est vide
146                                                RunState<=InitApp;
147                                 end if;
148                                 --Ram_busy<='0';
149                                 Libr.O.MemBusy<='0';
150                                 Libr.O.Instr_En<='0';
151                               
152                                adresse:=10;--DATAPTR;
153                               
154                                adresse_rd:=0;
155                                timeout:=0;
156                                --dcount<=0;
157                                sram.O.we<='0';
158                                        sram.O.ena<='0';
159                                        sram.O.enb<='0';
160                        -- synthesis translate_off
161                        if fopened='0' then 
162                        file_open(status,f, integer'image(Task_Id) & "test_file0.txt", APPEND_MODE);
163        --while not endfile(c_file_handle) loop
164                        --end if;
165               
166                                --write (l,string'("Ce fichier contient des resultats de la simulation ; ;" & " started at time ; " & time'image(now)));
167                                --report l.all;
168           -- writeline (f, l) ;
169                                fopened:='1';
170                        end if;
171                         -- synthesis translate_on
172                         when Fillmem =>
173                                        sram.O.we<='1';
174                                        sram.O.ena<='1';
175                                        sram.O.enb<='0';
176                                if Libr.I.Ramsel='0' then 
177                                       
178                                        sram.O.addr_wr<=std_logic_vector(to_unsigned(adresse,ADRLEN));
179                                        sram.O.data_in<=std_logic_vector(to_unsigned(dcount,8)); -- x"0f";
180                                        Libr.O.Instr_En<='0';
181                                        dcount:=dcount+1;
182                                       
183                                        if dcount=250 then
184                                                 bfill:=bfill+1;
185                                                 
186                                                 if bfill=4 then
187                                                  RunState<=WinCreate;
188                                                 else
189                                                        RunState<=nextfill;
190                                                end if;
191                                        else
192                                                adresse:=adresse+1;
193                                                RunState<=Fillmem;
194                                        end if;
195                        else -- attente de la libéraion de la mémoire
196                                timeout:=timeout+1;
197                                          if timeout=100 then
198                                                RunState<=st_timeout;
199                                          end if;
200                                                       
201                        end if;
202                when nextfill  =>   --prépare le prochain bloc mémoire qui sera rempli
203                                adresse:=250*bfill+10;
204                               
205                                dcount:=0;
206                                ct:=0;
207                                RunState<=Fillmem;
208                                Libr.O.Instr_En<='0';
209                                        sram.O.we<='1';
210                                        sram.O.ena<='1';
211                                        sram.O.enb<='0';
212                when InitApp =>
213                                --code pour Init
214                                dlen:=1;
215                                if ct=0 then
216                                -- synthesis translate_off
217                                write (l,string'("Dlen;"& integer'image(dlen) & " ;INIT1 " &  integer'image(Dlen)& "; " & image(MyRank) & "; started at ; " & real'image(rt(now))));
218                               
219                                report l.all;
220            writeline (f, l) ;
221                                -- synthesis translate_on
222                                end if;
223                                pMPI_Init(ct,Libr,Clk,SRam);
224                               
225                                adresse:=to_integer(unsigned(sram.O.addr_wr));
226                                adresse_rd:=to_integer(unsigned(sram.O.addr_rd));
227                               
228                                --if Libr.InitOk='1' then
229                                if ct=0 then 
230                                        RunState<=GetRank;
231                                        -- synthesis translate_off
232                                        write (l,string'("Dlen;" & integer'image(Dlen) & ";INIT2 " &  integer'image(Dlen) & ";" & image(MyRank) & ";  ended at  ; " & real'image(rt(now))));
233                                        report l.all;
234                                        writeline (f, l) ; 
235                                        -- synthesis translate_on
236                                end if;
237                               
238               
239               
240                when GetRank =>
241                if ct=0 then
242                                -- synthesis translate_off
243                                write (l,string'("Dlen;" & integer'image(Dlen)& ";Rank1 " &  integer'image(Dlen) & "; ; started  ; " & real'image(rt(now))));
244                                report l.all;
245            writeline (f, l) ; 
246                                -- synthesis translate_on
247                        end if;
248                        pMPI_Comm_rank(ct,Libr,sram,MPI_COMM_WORLD,MyRank);
249                        adresse_rd:=to_integer(unsigned(sram.O.addr_rd));
250                       
251                       
252                        if ct=0 then
253                                RunState<=FillMem;
254                                -- synthesis translate_off
255                                write (l,string'("Dlen;" & integer'image(dlen) & ";Rank2 " &  integer'image(Dlen) & ";" & image(MyRank) & "; ended at  ; " & real'image(rt(now))));
256                                report l.all;
257            writeline (f, l) ; 
258                                -- synthesis translate_on
259                        end if;
260                       
261               
262                when Wincreate => --par défaut la fenêtre 0 est utilisée !
263                  case MyRank is
264                    when x"0"=>
265                      Mygroup.grp<=x"0002";-- rank 1
266                      MyGroup.nb<=2;
267                      destRank:=1;
268                      DestAdr:=X"043F";
269                      nb_rma:=1;
270                    when x"1" =>
271                                      Mygroup.grp<=x"0000";-- rank 0
272                                      destRank:=0;
273                                      DestAdr:=X"043F";
274                    when x"2" =>
275                                      Mygroup.grp<=x"0000";-- rank
276                                      destRank:=0;
277                                      DestAdr:=X"044F";
278                    when x"3" =>
279                                      Mygroup.grp<=x"0000";-- rank
280                                      destRank:=0;
281                                      DestAdr:=X"045F";
282                    when others =>   --cas des processus spawn
283                                      Mygroup.grp<=x"0000";-- rank 0
284                                      destRank:=0;
285                 end case;
286                         RunState<=WinPost;
287                when WinPost =>
288                        if ct=0 then
289                                -- synthesis translate_off
290                                write (l,string'("Dlen;"& integer'image(dlen) & ";WPost1 " &  integer'image(Dlen) & "; ; started  ; " & real'image(rt(now))));
291                                report l.all;
292            writeline (f, l) ; 
293                                -- synthesis translate_on
294                        end if;
295                       
296                                pMPI_Win_Post(ct,Libr,sram,MyGroup,0,MyWin);
297                       
298                        if ct=0 then
299                          if spawn_on='1' then
300                                RunState<=WinWait;
301                                else
302                                  RunState<=WinStart;
303                                  end if;
304                                -- synthesis translate_off
305                                write (l,string'("Dlen;"& integer'image(dlen) & ";WPost2 " &  integer'image(Dlen) & ";" & image(MyRank) & "; ended at  ; " & real'image(rt(now))));
306                                report l.all;
307            writeline (f, l) ; 
308                                -- synthesis translate_on
309                        end if;
310                       
311                when WinStart =>
312                        if ct=0 then
313                                -- synthesis translate_off
314                                write (l,string'("Dlen;" & integer'image(dlen) & ";WStart1 " &  integer'image(Dlen) & "; ; started  ; " & real'image(rt(now))));
315                                report l.all;
316            writeline (f, l) ; 
317                                -- synthesis translate_on
318                        end if;
319                                pMPI_Win_start(ct,Libr,sram,MyGroup,0,MyWin);
320                                        adresse:=to_integer(unsigned(sram.O.addr_wr));
321                                        adresse_rd:=to_integer(unsigned(sram.O.addr_rd));
322                                       
323                                        dcount:=ct;
324                       
325                        if ct=0 then
326                                RunState<=PutData;
327                                -- synthesis translate_off
328                                write (l,string'("Dlen;" & integer'image(dlen) & ";WStart2 " &  integer'image(Dlen) & ";" & image(MyRank) & "; ended at  ; " & real'image(rt(now))));
329                                report l.all;
330            writeline (f, l) ; 
331                                -- synthesis translate_on
332                        end if;
333                       
334               
335                when putdata => --construire le packet pour le Put
336                               
337                                        --dlen:=251; ---
338                                        if ct=0 then
339                                        -- synthesis translate_off
340                                        write (l,string'("Dlen;" & integer'image(dlen) & ";PUT1 " & integer'image(dlen) & ";" & image(MyRank) & "; started at ; " & real'image(rt(now))));
341                                        report l.all;
342                                        writeline (f, l) ; 
343                                        -- synthesis translate_on
344                                        end if;
345                                         
346                                        SrcAdr:=X"000A";--std_logic_vector(to_unsigned(DATAPTR,ADRLEN));
347                                        --DestAdr:=X"033F";
348                                        pMPI_put(ct,Libr,Clk,Sram,SrcAdr,Dlen,MPI_int,destrank,DestAdr,Dlen,Mpi_int,Default_win);
349                                       
350                                        adresse:=to_integer(unsigned(sram.O.addr_wr));
351                                        adresse_rd:=to_integer(unsigned(sram.O.addr_rd));
352                                       
353                                        dcount:=ct;
354                                       
355                                        if ct=0 then
356                                                RunState<=GetData;
357                                        -- synthesis translate_off
358                                        report "Put of Process n°; " & image(MyRank) & "; ended at ; " & real'image(rt(now));
359                                        write (l,string'("Dlen;" & integer'image(dlen) & ";PUT2 " & integer'image(dlen) & ";" & image(MyRank) & "; ended at time ; " & real'image(rt(now))));
360                                        report l.all;
361                                        writeline (f, l) ;
362                                        -- synthesis translate_on
363                                        end if;
364                                       
365                               
366                        when getdata =>   --positionnement du mot de longueur des données
367                                        --dlen:=251; ---
368                                        if ct=0 then
369                                        -- synthesis translate_off
370                                        write (l,string'("Dlen;" & integer'image(dlen) & ";GET1; " & image(MyRank) & "; started at ; " & real'image(rt(now))));
371                                        report l.all;
372                                        writeline (f, l) ; 
373                                        -- synthesis translate_on
374                                        end if;
375                                       
376                                        SrcAdr:=X"006D";
377                                        DestAdr:=X"1400";
378                                        if unsigned(MyRank) = 0 then 
379                                        pMPI_GET(ct,Libr,Clk,Sram,SrcAdr,Dlen,MPI_int,destrank,DestAdr,Dlen,Mpi_int,Default_win);
380                                        else
381                                         
382                                                --pMPI_GET(ct,Libr,Clk,Sram,SrcAdr,Dlen,MPI_int,nb_rma,DestAdr,Dlen,Mpi_int,Default_win);
383                                        end if;
384                                        adresse:=to_integer(unsigned(sram.O.addr_wr));
385                                        adresse_rd:=to_integer(unsigned(sram.O.addr_rd));
386                                       
387                                        dcount:=ct;
388                                       
389                                        if ct=0 then
390                                          if unsigned(MyRank)/=0 then
391                                                RunState<=wincompleted;
392                                                else
393                                                  nb_rma:=nb_rma+1;
394                                                  if nb_rma=2 then 
395                                                    RunState<=wincompleted;
396                                                    nb_rma:=0;
397                                                   end if;
398                                                end if;
399                                                -- synthesis translate_off
400                                                assert ct/=0 report "GET_END " & integer'image(destrank)
401                                                                severity Warning ;
402                                                write (l,string'("Dlen ;" & integer'image(dlen) & ";GET2 " & integer'image(dlen) & ";" & image(MyRank) & "; ended at ; " & real'image(rt(now))));
403                                        report l.all;
404                                       
405                                        writeline (f, l) ; 
406                                                -- synthesis translate_on
407                                        end if;
408                               
409                                when WinCompleted =>
410                                if ct=0 then
411                                                -- synthesis translate_off
412                                                write (l,string'("Dlen ;" & integer'image(dlen) & ";Compl1 " & integer'image(dlen) & ";" & image(MyRank) & "; started at ; " & real'image(rt(now))));
413                                                report l.all;
414                                                writeline (f, l) ; 
415                                                -- synthesis translate_on
416                                        end if; 
417                                         pMPI_Win_Complete(ct,Libr,sram,MyWin );
418                                         adresse:=to_integer(unsigned(sram.O.addr_wr));
419                                        adresse_rd:=to_integer(unsigned(sram.O.addr_rd));
420                                       
421                                        if ct=0 then
422                                                RunState<=WinWait;     
423                                                -- synthesis translate_off
424                                                write (l,string'("Dlen ;" & integer'image(dlen) & ";Compl2 " & integer'image(dlen) & ";" & image(MyRank) & "; ended at ; " & real'image(rt(now))));
425                                                report l.all;
426                                                writeline (f, l) ;
427                                                -- synthesis translate_on
428                                               
429                                        end if;   
430                        when WinWait =>
431                                if ct=0 then
432                                                -- synthesis translate_off
433                                                write (l,string'("Dlen ;" & integer'image(dlen) & ";WAIT1 " & integer'image(dlen) & ";" & image(MyRank) & "; started at ; " & real'image(rt(now))));
434                                                report l.all;
435                                                writeline (f, l) ; 
436                                                -- synthesis translate_on
437                                        end if; 
438                                         pMPI_Win_wait(ct,Libr,sram,MyWin );
439                                         adresse:=to_integer(unsigned(sram.O.addr_wr));
440                                        adresse_rd:=to_integer(unsigned(sram.O.addr_rd));
441                                       
442                                        if ct=0 then
443                                          if Libr.I.Spawned='1' then
444                                                RunState<=Finalize;     
445                                                elsif spawn_on='1' then
446                                                  RunState<=Finalize;   
447                                                else
448                                                  RunState<=MpiSpawn;   
449                                                end if;
450                                                -- synthesis translate_off
451                                                write (l,string'("Dlen ;" & integer'image(dlen) & ";WAIT2 " & integer'image(dlen) & ";" & image(MyRank) & "; ended at ; " & real'image(rt(now))));
452                                                report l.all;
453                                                writeline (f, l) ;
454                                                -- synthesis translate_on
455                                               
456                                        end if;   
457                                                       
458                        when MpiSpawn =>
459                                if ct=0 then
460                                                -- synthesis translate_off
461                                                write (l,string'("Dlen ;" & integer'image(dlen) & ";Spawn1 " & integer'image(dlen) & ";" & image(MyRank) & "; started at ; " & real'image(rt(now))));
462                                                report l.all;
463                                                writeline (f, l) ; 
464                                                -- synthesis translate_on
465                                        end if; 
466                                        --(NextCtx : inout natural;signal Interf:inout Core_io;signal SysRam :inout typ_dpram; 
467
468                                                maxprocs:=2;
469                                         pMPI_Comm_Spawn(ct,Libr,sram,command,argv,maxprocs,info,root,comm,intercomm,array_of_errcodes);
470                                         adresse:=to_integer(unsigned(sram.O.addr_wr));
471                                        adresse_rd:=to_integer(unsigned(sram.O.addr_rd));
472                                       
473                                        if ct=0 then
474                                          if unsigned(MyRank)=0 then
475                                              Spawn_on:='1';
476                                               Mygroup.grp<=x"000C";-- rank 3,4
477                                      destRank:=0;
478                                              runstate<=WinPost;
479                                            else
480                                                        RunState<=Finalize;     
481                                                end if;
482                                       
483                                                -- synthesis translate_off
484                                                write (l,string'("Dlen ;" & integer'image(dlen) & ";Spawn2 " & integer'image(dlen) & ";" & image(MyRank) & "; ended at ; " & real'image(rt(now))));
485                                                report l.all;
486                                                writeline (f, l) ;
487                                                -- synthesis translate_on
488                                               
489                                        end if;                         
490                        when finalize =>
491                                        if ct=0 then
492                                                -- synthesis translate_off
493                                                write (l,string'("Dlen ;" & integer'image(dlen) & ";FINALIZE1 " & integer'image(dlen) & ";" & image(MyRank) & "; started at ; " & real'image(rt(now))));
494                                                report l.all;
495                                                writeline (f, l) ; 
496                                                -- synthesis translate_on
497                                        end if; 
498                                         sram.O.we<='0';
499                                        sram.O.ena<='0';
500                                        sram.O.enb<='0';
501                                        if ct=0 then
502                                                RunState<=start;       
503                                                -- synthesis translate_off
504                                                write (l,string'("Dlen ;" & integer'image(dlen) & ";FINALIZE2 " & integer'image(dlen) & ";" & image(MyRank) & "; ended at ; " & real'image(rt(now))));
505                                                report l.all;
506                                                writeline (f, l) ;
507                                                file_close(f); 
508                                                -- synthesis translate_on
509                                        end if;   
510               
511                        when st_timeout =>
512                         
513                                        sram.O.we<='0';
514                                        sram.O.ena<='0';
515                                        sram.O.enb<='0';
516               
517                          RunState<=start;
518                        end case;
519                        ct_state<=ct; --pour débogage
520                end if;
521        end if;
522
523  end process pPutGet; 
524
525end a2;
526
Note: See TracBrowser for help on using the repository browser.