1
1
openmpi/ompi/mca/coll/ml/coll_ml_allocation.c
Nathan Hjelm 1a021b8f2d coll/ml: add support for blocking and non-blocking allreduce, reduce, and
allgather.

The new collectives provide a signifigant performance increase over tuned for
small and medium messages. We are initially setting the priority lower than
tuned until this has had some time to soak in the trunk. Please set
coll_ml_priority to 90 for MTT runs.

Credit for this work goes to Manjunath Gorentla Venkata (ORNL), Pavel Shamis (ORNL),
and Nathan Hjelm (LANL).

Commit details (for reference):

Import ORNL's collectives for MPI_Allreduce, MPI_Reduce, and MPI_Allgather.

We need to take the basesmuma header into account when calculating the
ptpcoll small message thresholds. Add a define to bcol.h indicating the
maximum header size so we can take the header into account while not
making ptpcoll dependent on information from basesmuma.

This resolves an issue with allreduce where ptpcoll overwrites the
header of the next buffer in the basesmuma bank.

Fix reduce and make a sequential collective launcher in coll_ml_inlines.h

The root calculation for reduce was wrong for any root != 0. There are
four possibilities for the root:

 - The root is not the current process but is in the current hierarchy. In
   this case the root is the index of the global root as specified in the
   root vector.

 - The root is not the current process and is not in the next level of the
   hierarchy. In this case 0 must be the local root since this process will
   never communicate with the real root.

 - The root is not the current process but will be in next level of the
   hierarchy. In this case the current process must be the root.

 - I am the root. The root is my index.

Tested with IMB which rotates the root on every call to MPI_Reduce. Consider
IMB the reproducer for the issue this commit solves.

Make the bcast algorithm decision an enumerated variable

Resolve various asset failures when destructing coll ml requests.

Two issues:

 - Always reset the request to be invalid before returning it to the
   free list. This will avoid an asset in ompi_request_t's destructor.
   OMPI_REQUEST_FINI does this (and also releases the fortran handle
   index).

 - Never explicitly construct or destruct the superclass of an opal
   object. This screws up the class function tables and will cause
   either an assert failure or a segmentation fault when destructing
   coll ml requests.

Cleanup allgather.

I removed the duplicate non-blocking and blocking functions and modeled
the cleanup after what I found in allreduce. Also cleaned up the code
somewhat.

Don't bother copying from the send to the recieve buffer in
bcol_basesmuma_allreduce_intra_fanin_fanout if the pointers are the
same.

The eliminates a warning about memcpy and aliasing and avoids an
unnecessary call to memcpy.

Alwasy call CHECK_AND_RELEASE on memsync collectives.

There was a call to OBJ_RELEASE on the collective communicator but
because CHECK_AND_RECYLCE was never called there was not matching call
to OBJ_RELEASE. This caused coll ml to leak communicators.

Make allreduce use the sequential collective launcher in coll_ml_inlines.h

Just launch the next collective in the component progress.

I am a little unsure about this patch. There appears to be some sort
of race between collectives that causes buffer exhaustion in some cases
(IMB Allreduce is a reproducer). Changing progress to only launch the
next bcol seems to resolve the issue but might not be the best fix.

Note that I see little-no performance penalty for this change.

Fix allreduce when there are extra sources.

There was an issue with the buffer offset calculation when there are
extra sources. In the case of extra sources == 1 the offset was set
to buffer_size (just past the header of the next buffer). I adjusted
the buffer size to take into accoun the maximum header size (see the
earlier commit that added this) and simplified the offset calculation.

Make reduce/allreduce non-blocking. This is required for MPI_Comm_idup
to work correctly.

This has been tested with various layouts using the ibm testsuite and
imb and appears to have the same performance as the old blocking version.

Fix allgather for non-contiguous layouts and simplify parsing the
topology.

Some things in this patch:

 - There were several comments to the effect that level 0 of the
   hierarchy MUST contain all of the ranks. At least one function
   made this assumption but it was not true. I changed the sbgp
   components and the coll ml initization code to enforce this
   requirement.

 - Ensure that hierarchy level 0 has the ranks in the correct
   scatter gather order. This removes the need for a separate
   sort list and fixes the offset calculation for allgather.

 - There were several passes over the hierarchy to determine
   properties of the hierarchy. I eliminated these extra passes
   and the memory allocation associated with them and calculate the
   tree properties on the fly. The same DFS recursion also handles
   the re-order of level 0.

All these changes have been verified with MPI_Allreduce, MPI_Reduce, and
MPI_Allgather. All functions now pass all IBM/Open MPI, and IMB tests.

coll/ml: correct pointer usage for MPI_BOTTOM

Since contiguous datatypes are copied via memcpy (bypassing the convertor) we
need to adjust for the lb of the datatype. This corrects problems found testing
code that uses MPI_BOTTOM (NULL) as the send pointer.

Add fallback collectives for allreduce and reduce.

cmr=v1.7.5:reviewer=pasha

This commit was SVN r30363.
2014-01-22 15:39:19 +00:00

217 строки
6.8 KiB
C

/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2009-2012 Oak Ridge National Laboratory. All rights reserved.
* Copyright (c) 2009-2012 Mellanox Technologies. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */
#include "coll_ml.h"
#include "coll_ml_inlines.h"
#include "coll_ml_allocation.h"
long memory_buffer_index;
ml_memory_block_desc_t *mca_coll_ml_allocate_block(struct mca_coll_ml_component_t *ml_component,
ml_memory_block_desc_t *ml_memblock)
{
ml_memory_block_desc_t *ret = NULL;
ml_memory_block_desc_t *memory_block = NULL;
mca_coll_ml_lmngr_t *memory_manager = NULL;
if (ml_memblock) {
ML_ERROR(("Memory already allocated - expecting NULL pointer"));
return ret;
}
memory_block = (ml_memory_block_desc_t*) calloc(1, sizeof(ml_memory_block_desc_t));
if (NULL == memory_block){
ML_ERROR(("Couldn't allocate memory for ml_memblock"));
return ret;
}
memory_manager = &ml_component->memory_manager;
memory_block->block = mca_coll_ml_lmngr_alloc(memory_manager);
memory_block->size_block = memory_manager->list_block_size;
if (!memory_block->block){
ML_ERROR(("lmngr failed."));
ret = NULL;
goto exit_ERROR;
}
return memory_block;
exit_ERROR:
if (memory_block){
free(memory_block);
return ret;
}
return ret;
}
void mca_coll_ml_free_block (ml_memory_block_desc_t *ml_memblock)
{
if (!ml_memblock)
return;
if (ml_memblock->buffer_descs){
free(ml_memblock->buffer_descs);
}
mca_coll_ml_lmngr_free(ml_memblock->block);
free(ml_memblock->bank_release_counters);
free(ml_memblock->ready_for_memsync);
free(ml_memblock->bank_is_busy);
free(ml_memblock);
}
int mca_coll_ml_initialize_block(ml_memory_block_desc_t *ml_memblock,
uint32_t num_buffers,
uint32_t num_banks,
uint32_t buffer_size,
int32_t data_offset,
opal_list_t *bcols_in_use)
{
int ret = OMPI_SUCCESS;
uint32_t bank_loop, buff_loop;
uint64_t addr_offset = 0;
ml_payload_buffer_desc_t *pbuff_descs = NULL,*pbuff_desc = NULL;
if (NULL == ml_memblock){
ML_ERROR(("Memory block not initialized"));
ret = OMPI_ERROR;
goto exit_ERROR;
}
if (ml_memblock->size_block < (num_buffers * num_banks * buffer_size) ){
ML_ERROR(("Not enough memory for all buffers and banks in the memory block"));
ret = OMPI_ERROR;
goto exit_ERROR;
}
pbuff_descs = (ml_payload_buffer_desc_t*) malloc(sizeof(ml_payload_buffer_desc_t)
* num_banks * num_buffers);
for(bank_loop = 0; bank_loop < num_banks; bank_loop++)
for(buff_loop = 0; buff_loop < num_buffers; buff_loop++){
pbuff_desc = &pbuff_descs[bank_loop*num_buffers + buff_loop];
pbuff_desc->base_data_addr = (void *)
((char *)ml_memblock->block->base_addr + addr_offset);
pbuff_desc->data_addr = (void *)
((char *)pbuff_desc->base_data_addr + (size_t)data_offset);
addr_offset+=buffer_size;
pbuff_desc->buffer_index = BUFFER_INDEX(bank_loop,num_buffers,buff_loop);
pbuff_desc->bank_index=bank_loop;
pbuff_desc->generation_number=0;
}
/* Initialize ml memory block */
/* gvm FIX:This counter when zero indicates that the bank is ready for
* recycle. This is initialized to number of bcol components as each bcol is responsible for
* releasing the buffers of a bank. This initialization will have
* faulty behavior, example in case of multiple interfaces, when more than
* one bcol module of the component type is in use.
*/
ml_memblock->bank_release_counters = (uint32_t *) calloc(num_banks, sizeof(uint32_t));
if (NULL == ml_memblock->bank_release_counters) {
ret = OMPI_ERR_OUT_OF_RESOURCE;
goto exit_ERROR;
}
ml_memblock->ready_for_memsync = (bool *) calloc(num_banks, sizeof(bool));
if (NULL == ml_memblock->ready_for_memsync) {
ret = OMPI_ERR_OUT_OF_RESOURCE;
goto exit_ERROR;
}
ml_memblock->bank_is_busy = (bool *) calloc(num_banks, sizeof(bool));
if (NULL == ml_memblock->bank_is_busy) {
ret = OMPI_ERR_OUT_OF_RESOURCE;
goto exit_ERROR;
}
/* Set index for first bank to sync */
ml_memblock->memsync_counter = 0;
/* use first bank and first buffer */
ml_memblock->next_free_buffer = 0;
ml_memblock->block_addr_offset = addr_offset;
ml_memblock->num_buffers_per_bank = num_buffers;
ml_memblock->num_banks = num_banks;
ml_memblock->size_buffer = buffer_size;
ml_memblock->buffer_descs = pbuff_descs;
return ret;
exit_ERROR:
/* Free all buffer descriptors */
if (pbuff_descs){
free(pbuff_descs);
}
return ret;
}
ml_payload_buffer_desc_t *mca_coll_ml_alloc_buffer (mca_coll_ml_module_t *module)
{
uint64_t bindex;
uint32_t bank, buffer, num_buffers;
ml_memory_block_desc_t *ml_memblock = module->payload_block;
ml_payload_buffer_desc_t *pbuff_descs = NULL,
*ml_membuffer = NULL;
/* Return a buffer */
num_buffers = ml_memblock->num_buffers_per_bank;
pbuff_descs = ml_memblock->buffer_descs;
bindex = ml_memblock->next_free_buffer;
buffer = bindex % num_buffers;
bank = bindex/num_buffers;
ML_VERBOSE(10, ("ML allocator: allocating buffer index %d, bank index %d", buffer, bank));
/* First buffer in bank, use next bank */
if (0 == buffer) {
if(!ml_memblock->bank_is_busy[bank]) {
/* the bank is free, mark it busy */
ml_memblock->bank_is_busy[bank] = true;
ML_VERBOSE(10, ("ML allocator: reset bank %d to value %d", bank,
ml_memblock->bank_release_counters[bank]));
} else {
/* the bank is busy, return NULL and upper layer will handle it */
ML_VERBOSE(10, ("No free payload buffers are available for use."
" Next memory bank is still used by one of bcols"));
return NULL;
}
}
assert(true == ml_memblock->bank_is_busy[bank]);
ml_membuffer = &pbuff_descs[bindex];
ML_VERBOSE(10, ("ML allocator: ml buffer index %d", bindex));
/* Compute next free buffer */
buffer = (buffer == num_buffers - 1) ? 0 : buffer + 1;
if (0 == buffer) {
bank = (bank == ml_memblock->num_banks - 1) ? 0 : bank + 1;
}
ml_memblock->next_free_buffer = BUFFER_INDEX(bank,num_buffers,buffer);
return ml_membuffer;
}