18
18
***********************************************************************/
19
19
20
20
#ifdef HAVE_CONFIG_H
21
- # include <config.h>
21
+ # include <config.h>
22
22
#endif
23
23
#include <stdlib.h>
24
24
#include <stdio.h>
33
33
#include "global.h"
34
34
#include "DirectPut.h"
35
35
36
+ // actual number of directions
37
+ unsigned int spi_num_dirs = NUM_DIRS ;
36
38
// total Message Size
37
- uint64_t totalMessageSize ;
39
+ // in bytes!
38
40
uint64_t totalMessageSize ;
39
41
// Allocate static memory for descriptors
40
42
char SPIDescriptorsMemory [ NUM_DIRS * sizeof (MUHWI_Descriptor_t ) + 64 ];
@@ -63,9 +65,6 @@ struct {
63
65
uint8_t hintsE ;
64
66
} nb2dest [NUM_DIRS ];
65
67
66
- // in bytes
67
- uint64_t totalMessageSize ;
68
-
69
68
// receive counter
70
69
volatile uint64_t recvCounter ;
71
70
@@ -170,7 +169,8 @@ void setup_mregions_bats_counters(const int bufferSize) {
170
169
}
171
170
172
171
173
- void create_descriptors (MUHWI_Descriptor_t * descriptors , uint64_t * messageSizes , uint64_t * soffsets , uint64_t * roffsets ) {
172
+ void create_descriptors (MUHWI_Descriptor_t * descriptors , uint64_t * messageSizes , uint64_t * soffsets ,
173
+ uint64_t * roffsets , const unsigned int num_dirs ) {
174
174
uint64_t anyFifoMap =
175
175
MUHWI_DESCRIPTOR_TORUS_FIFO_MAP_AM |
176
176
MUHWI_DESCRIPTOR_TORUS_FIFO_MAP_AP |
@@ -188,7 +188,7 @@ void create_descriptors(MUHWI_Descriptor_t * descriptors, uint64_t * messageSize
188
188
189
189
// loop over directions
190
190
// CHECK offset needs to be adjusted for QCD case
191
- for (int i = 0 ; i < 8 ; i ++ ) {
191
+ for (unsigned int i = 0 ; i < num_dirs ; i ++ ) {
192
192
// Injection Direct Put Descriptor Information Structure
193
193
MUSPI_Pt2PtDirectPutDescriptorInfo_t dinfo ;
194
194
@@ -244,14 +244,14 @@ void create_descriptors(MUHWI_Descriptor_t * descriptors, uint64_t * messageSize
244
244
fprintf (stderr , "MUSPI_CreatePt2PtDirectPutDescriptor failed with rc=%d\n" ,rc );
245
245
exit (1 );
246
246
}
247
-
248
247
}
249
248
}
250
249
251
250
252
251
int get_destinations (int * mypers ) {
253
252
254
253
int tmp [6 ];
254
+ #if (defined PARALLELT || defined PARALLELXT || defined PARALLELXYT || defined PARALLELXYZT )
255
255
MPI_Status mstatus ;
256
256
MPI_Sendrecv ((void * )mypers , 6 , MPI_INT , g_nb_t_up , 0 ,
257
257
(void * )tmp , 6 , MPI_INT , g_nb_t_dn , 0 ,
@@ -261,7 +261,8 @@ int get_destinations(int * mypers) {
261
261
(void * )tmp , 6 , MPI_INT , g_nb_t_up , 1 ,
262
262
g_cart_grid , & mstatus );
263
263
MUSPI_SetUpDestination ( & nb2dest [0 ].dest , tmp [0 ], tmp [1 ], tmp [2 ], tmp [3 ], tmp [4 ] );
264
-
264
+ #endif
265
+ #if (defined PARALLELXT || defined PARALLELXYT || defined PARALLELXYZT )
265
266
MPI_Sendrecv ((void * )mypers , 6 , MPI_INT , g_nb_x_up , 2 ,
266
267
(void * )tmp , 6 , MPI_INT , g_nb_x_dn , 2 ,
267
268
g_cart_grid , & mstatus );
@@ -270,7 +271,8 @@ int get_destinations(int * mypers) {
270
271
(void * )tmp , 6 , MPI_INT , g_nb_x_up , 3 ,
271
272
g_cart_grid , & mstatus );
272
273
MUSPI_SetUpDestination ( & nb2dest [2 ].dest , tmp [0 ], tmp [1 ], tmp [2 ], tmp [3 ], tmp [4 ] );
273
-
274
+ #endif
275
+ #if (defined PARALLELXYT || defined PARALLELXYZT )
274
276
MPI_Sendrecv ((void * )mypers , 6 , MPI_INT , g_nb_y_up , 4 ,
275
277
(void * )tmp , 6 , MPI_INT , g_nb_y_dn , 4 ,
276
278
g_cart_grid , & mstatus );
@@ -279,7 +281,8 @@ int get_destinations(int * mypers) {
279
281
(void * )tmp , 6 , MPI_INT , g_nb_y_up , 5 ,
280
282
g_cart_grid , & mstatus );
281
283
MUSPI_SetUpDestination ( & nb2dest [4 ].dest , tmp [0 ], tmp [1 ], tmp [2 ], tmp [3 ], tmp [4 ] );
282
-
284
+ #endif
285
+ #if (defined PARALLELXYZT )
283
286
MPI_Sendrecv ((void * )mypers , 6 , MPI_INT , g_nb_z_up , 6 ,
284
287
(void * )tmp , 6 , MPI_INT , g_nb_z_dn , 6 ,
285
288
g_cart_grid , & mstatus );
@@ -288,7 +291,7 @@ int get_destinations(int * mypers) {
288
291
(void * )tmp , 6 , MPI_INT , g_nb_z_up , 7 ,
289
292
g_cart_grid , & mstatus );
290
293
MUSPI_SetUpDestination ( & nb2dest [6 ].dest , tmp [0 ], tmp [1 ], tmp [2 ], tmp [3 ], tmp [4 ] );
291
-
294
+ #endif
292
295
return (0 );
293
296
}
294
297
@@ -309,8 +312,7 @@ typedef struct msg_InjFifoInfo
309
312
310
313
uint64_t msg_InjFifoInject ( msg_InjFifoHandle_t injFifoHandle ,
311
314
uint32_t relativeFifoId ,
312
- MUHWI_Descriptor_t * descPtr )
313
- {
315
+ MUHWI_Descriptor_t * descPtr ) {
314
316
msg_InjFifoInfo_t * info = (msg_InjFifoInfo_t * )injFifoHandle .pOpaqueObject ;
315
317
316
318
uint32_t globalFifoId = (info -> startingSubgroupId * BGQ_MU_NUM_INJ_FIFOS_PER_SUBGROUP ) +
@@ -320,11 +322,10 @@ uint64_t msg_InjFifoInject ( msg_InjFifoHandle_t injFifoHandle,
320
322
uint64_t rc = MUSPI_InjFifoInject (MUSPI_IdToInjFifo ( globalFifoId % BGQ_MU_NUM_INJ_FIFOS_PER_SUBGROUP ,
321
323
& info -> subgroup [subgroupId ] ),
322
324
descPtr );
323
- return rc ;
325
+ return rc ;
324
326
}
325
327
326
- void msg_InjFifoTerm ( msg_InjFifoHandle_t injFifoHandle )
327
- {
328
+ void msg_InjFifoTerm ( msg_InjFifoHandle_t injFifoHandle ) {
328
329
return ; /*Simple library do nothing! */
329
330
}
330
331
@@ -333,8 +334,8 @@ int msg_InjFifoInit ( msg_InjFifoHandle_t *injFifoHandlePtr,
333
334
uint32_t startingFifoId ,
334
335
uint32_t numFifos ,
335
336
size_t fifoSize ,
336
- Kernel_InjFifoAttributes_t * injFifoAttrs )
337
- {
337
+ Kernel_InjFifoAttributes_t * injFifoAttrs ) {
338
+
338
339
void * buffer = NULL ;
339
340
uint32_t endingFifoId ; // Relative to a subgroup
340
341
uint32_t numFifosInSubgroup ;
@@ -343,16 +344,17 @@ int msg_InjFifoInit ( msg_InjFifoHandle_t *injFifoHandlePtr,
343
344
uint32_t fifoIds [BGQ_MU_NUM_INJ_FIFOS_PER_SUBGROUP ];
344
345
Kernel_InjFifoAttributes_t attrs [BGQ_MU_NUM_INJ_FIFOS_PER_SUBGROUP ];
345
346
Kernel_InjFifoAttributes_t defaultAttrs ;
346
- unsigned int i ;
347
347
uint64_t lock_cache ;
348
348
349
349
memset ( & defaultAttrs , 0x00 , sizeof (defaultAttrs ) );
350
- if ( injFifoAttrs == NULL ) injFifoAttrs = & defaultAttrs ;
350
+ if (injFifoAttrs == NULL ) {
351
+ injFifoAttrs = & defaultAttrs ;
352
+ }
351
353
352
354
// Malloc space for the info structure
353
355
msg_InjFifoInfo_t * info ;
354
356
info = (msg_InjFifoInfo_t * ) memalign (32 , sizeof (msg_InjFifoInfo_t ));
355
- if ( !info ) return -1 ;
357
+ if ( !info ) return -1 ;
356
358
357
359
// Initialize the info structure
358
360
info -> startingSubgroupId = startingSubgroupId ;
@@ -361,94 +363,87 @@ int msg_InjFifoInit ( msg_InjFifoHandle_t *injFifoHandlePtr,
361
363
info -> numSubgroups = 0 ;
362
364
363
365
// Malloc space for the injection fifos. They are 64-byte aligned.
364
- for (i = 0 ; i < numFifos ; i ++ )
365
- {
366
- info -> fifoPtr [i ] = (uint64_t * )memalign (64 , fifoSize );
367
- if ( !info -> fifoPtr [i ] ) return -1 ;
368
- }
366
+ for (unsigned int i = 0 ; i < numFifos ; i ++ ) {
367
+ info -> fifoPtr [i ] = (uint64_t * )memalign (64 , fifoSize );
368
+ if ( !info -> fifoPtr [i ] ) return -1 ;
369
+ }
369
370
370
371
// Process one subgroup at a time.
371
372
// - Allocate the fifos.
372
373
// - Init the MU MMIO for the fifos.
373
374
// - Activate the fifos.
374
- while ( numFifos > 0 )
375
- {
376
- info -> numSubgroups ++ ;
377
-
378
- // startingFifoId is the starting fifo number relative to the
379
- // subgroup we are working on.
380
- // Determine endingFifoId, the ending fifo number relative to
381
- // the subgroup we are working on.
382
- endingFifoId = startingFifoId + numFifos - 1 ;
383
- if ( endingFifoId > (BGQ_MU_NUM_INJ_FIFOS_PER_SUBGROUP - 1 ) )
384
- endingFifoId = BGQ_MU_NUM_INJ_FIFOS_PER_SUBGROUP - 1 ;
385
- numFifosInSubgroup = endingFifoId - startingFifoId + 1 ;
386
- info -> numFifosInSubgroup [subgroupId ] = numFifosInSubgroup ;
387
-
388
- // Init structures for allocating the fifos...
389
- // - fifo Ids
390
- // - attributes
391
- for (i = 0 ; i < numFifosInSubgroup ; i ++ )
392
- {
393
- fifoIds [i ] = startingFifoId + i ;
394
- memcpy (& attrs [i ],injFifoAttrs ,sizeof (attrs [i ]));
395
- /* printf("Attrs[%u] = 0x%x\n",i,*((uint32_t*)&attrs[i])); */
396
- /* printf("InjFifoInit: fifoIds[%u]=%u\n",i,fifoIds[i]); */
397
- }
398
-
399
- // Allocate the fifos
400
- rc = Kernel_AllocateInjFifos (subgroupId ,
401
- & info -> subgroup [subgroupId ],
402
- numFifosInSubgroup ,
403
- fifoIds ,
404
- attrs );
375
+ while ( numFifos > 0 ) {
376
+ info -> numSubgroups ++ ;
377
+
378
+ // startingFifoId is the starting fifo number relative to the
379
+ // subgroup we are working on.
380
+ // Determine endingFifoId, the ending fifo number relative to
381
+ // the subgroup we are working on.
382
+ endingFifoId = startingFifoId + numFifos - 1 ;
383
+ if ( endingFifoId > (BGQ_MU_NUM_INJ_FIFOS_PER_SUBGROUP - 1 ) ) {
384
+ endingFifoId = BGQ_MU_NUM_INJ_FIFOS_PER_SUBGROUP - 1 ;
385
+ }
386
+ numFifosInSubgroup = endingFifoId - startingFifoId + 1 ;
387
+ info -> numFifosInSubgroup [subgroupId ] = numFifosInSubgroup ;
388
+
389
+ // Init structures for allocating the fifos...
390
+ // - fifo Ids
391
+ // - attributes
392
+ for (unsigned int i = 0 ; i < numFifosInSubgroup ; i ++ ) {
393
+ fifoIds [i ] = startingFifoId + i ;
394
+ memcpy (& attrs [i ], injFifoAttrs , sizeof (attrs [i ]));
395
+ }
396
+
397
+ // Allocate the fifos
398
+ rc = Kernel_AllocateInjFifos (subgroupId ,
399
+ & info -> subgroup [subgroupId ],
400
+ numFifosInSubgroup ,
401
+ fifoIds ,
402
+ attrs );
403
+ if ( rc ) {
404
+ printf ("msg_InjFifoInit: Kernel_AllocateInjFifos failed with rc=%d\n" ,rc );
405
+ return rc ;
406
+ }
407
+
408
+ // Init the MU MMIO for the fifos.
409
+ for (unsigned int i = 0 ; i < numFifosInSubgroup ; i ++ ) {
410
+ Kernel_MemoryRegion_t memRegion ;
411
+ rc = Kernel_CreateMemoryRegion ( & memRegion ,
412
+ info -> fifoPtr [numFifos - i - 1 ],
413
+ fifoSize );
405
414
if ( rc ) {
406
- printf ("msg_InjFifoInit: Kernel_AllocateInjFifos failed with rc=%d\n" ,rc );
407
- return rc ;
415
+ printf ("msg_InjFifoInit: Kernel_CreateMemoryRegion failed with rc=%d\n" ,rc );
416
+ return rc ;
408
417
}
409
-
410
- // Init the MU MMIO for the fifos.
411
- for (i = 0 ; i < numFifosInSubgroup ; i ++ )
412
- {
413
- Kernel_MemoryRegion_t memRegion ;
414
- rc = Kernel_CreateMemoryRegion ( & memRegion ,
415
- info -> fifoPtr [numFifos - i - 1 ],
416
- fifoSize );
417
- if ( rc ) {
418
- printf ("msg_InjFifoInit: Kernel_CreateMemoryRegion failed with rc=%d\n" ,rc );
419
- return rc ;
420
- }
421
-
422
- rc = Kernel_InjFifoInit (& info -> subgroup [subgroupId ],
423
- fifoIds [i ],
424
- & memRegion ,
425
- (uint64_t )info -> fifoPtr [numFifos - i - 1 ] -
426
- (uint64_t )memRegion .BaseVa ,
427
- fifoSize - 1 );
428
- if ( rc ) {
429
- printf ("msg_InjFifoInit: Kernel_InjFifoInit failed with rc=%d\n" ,rc );
430
- return rc ;
431
- }
432
-
433
- /* TRACE(("HW freespace=%lx\n", MUSPI_getHwFreeSpace (MUSPI_IdToInjFifo (fifoIds[i],&info->subgroup[subgroupId]))))
434
- ; */
435
- }
436
-
437
- // Activate the fifos.
438
- rc = Kernel_InjFifoActivate (& info -> subgroup [subgroupId ],
439
- numFifosInSubgroup ,
440
- fifoIds ,
441
- KERNEL_INJ_FIFO_ACTIVATE );
418
+
419
+ // initialise the Fifos
420
+ rc = Kernel_InjFifoInit (& info -> subgroup [subgroupId ],
421
+ fifoIds [i ],
422
+ & memRegion ,
423
+ (uint64_t )info -> fifoPtr [numFifos - i - 1 ] -
424
+ (uint64_t )memRegion .BaseVa ,
425
+ fifoSize - 1 );
442
426
if ( rc ) {
443
- printf ("msg_InjFifoInit: Kernel_InjFifoActivate failed with rc=%d\n" ,rc );
444
- return rc ;
427
+ printf ("msg_InjFifoInit: Kernel_InjFifoInit failed with rc=%d\n" ,rc );
428
+ return rc ;
445
429
}
446
-
447
- startingFifoId = 0 ; // Next subgroup will start at fifo 0.
448
-
449
- subgroupId ++ ; // Next subgroup.
450
- numFifos -= numFifosInSubgroup ;
451
430
}
431
+
432
+ // Activate the fifos.
433
+ rc = Kernel_InjFifoActivate (& info -> subgroup [subgroupId ],
434
+ numFifosInSubgroup ,
435
+ fifoIds ,
436
+ KERNEL_INJ_FIFO_ACTIVATE );
437
+ if ( rc ) {
438
+ printf ("msg_InjFifoInit: Kernel_InjFifoActivate failed with rc=%d\n" ,rc );
439
+ return rc ;
440
+ }
441
+
442
+ startingFifoId = 0 ; // Next subgroup will start at fifo 0.
443
+
444
+ subgroupId ++ ; // Next subgroup.
445
+ numFifos -= numFifosInSubgroup ;
446
+ }
452
447
453
448
injFifoHandlePtr -> pOpaqueObject = (void * )info ;
454
449
return 0 ;
0 commit comments