root/ompi/mca/pml/ob1/pml_ob1_progress.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_pml_ob1_process_pending_cuda_async_copies
  2. mca_pml_ob1_enable_progress
  3. mca_pml_ob1_progress

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2008 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2017      Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 #include "ompi_config.h"
  23 
  24 #include "pml_ob1.h"
  25 #include "pml_ob1_sendreq.h"
  26 #include "ompi/mca/bml/base/base.h"
  27 #if OPAL_CUDA_SUPPORT
  28 #include "opal/mca/common/cuda/common_cuda.h"
  29 #include "pml_ob1_recvreq.h"
  30 #include "opal/runtime/opal_params.h"
  31 
  32 /**
  33  * Return the number of completed events allowing the upper level
  34  * to know when no pending events are expected so that it can
  35  * unregister the progress function.
  36  */
  37 static inline int mca_pml_ob1_process_pending_cuda_async_copies(void)
  38 {
  39     mca_btl_base_descriptor_t *frag;
  40     int progress, count = 0;
  41 
  42     do {
  43         progress = progress_one_cuda_htod_event(&frag);
  44         if (1 == progress) {
  45             /* Call the finish function to make progress. */
  46             mca_pml_ob1_recv_request_frag_copy_finished(NULL, NULL, frag, 0);
  47             count++;
  48         }
  49     } while (progress > 0);
  50     /* Consider progressing dtoh events here in future */
  51 
  52     return count;
  53 }
  54 #endif /* OPAL_CUDA_SUPPORT */
  55 
  56 static opal_atomic_int32_t mca_pml_ob1_progress_needed = 0;
  57 int mca_pml_ob1_enable_progress(int32_t count)
  58 {
  59     int32_t progress_count = OPAL_ATOMIC_ADD_FETCH32(&mca_pml_ob1_progress_needed, count);
  60     if( 1 < progress_count )
  61         return 0;  /* progress was already on */
  62 
  63     opal_progress_register(mca_pml_ob1_progress);
  64     return 1;
  65 }
  66 
  67 int mca_pml_ob1_progress(void)
  68 {
  69     int i, queue_length = opal_list_get_size(&mca_pml_ob1.send_pending);
  70     int j, completed_requests = 0;
  71     bool send_succedded;
  72 
  73 #if OPAL_CUDA_SUPPORT
  74     if (opal_cuda_support)
  75         completed_requests += mca_pml_ob1_process_pending_cuda_async_copies();
  76 #endif /* OPAL_CUDA_SUPPORT */
  77 
  78     for( i = 0; i < queue_length; i++ ) {
  79         mca_pml_ob1_send_pending_t pending_type = MCA_PML_OB1_SEND_PENDING_NONE;
  80         mca_pml_ob1_send_request_t* sendreq;
  81         mca_bml_base_endpoint_t* endpoint;
  82 
  83         sendreq = get_request_from_send_pending(&pending_type);
  84         if(OPAL_UNLIKELY(NULL == sendreq))
  85             break;
  86 
  87         switch(pending_type) {
  88         case MCA_PML_OB1_SEND_PENDING_NONE:
  89             assert(0);
  90             return 0;
  91         case MCA_PML_OB1_SEND_PENDING_SCHEDULE:
  92             if( mca_pml_ob1_send_request_schedule_exclusive(sendreq) ==
  93                 OMPI_ERR_OUT_OF_RESOURCE ) {
  94                 return 0;
  95             }
  96             completed_requests++;
  97             break;
  98         case MCA_PML_OB1_SEND_PENDING_START:
  99             MCA_PML_OB1_SEND_REQUEST_RESET(sendreq);
 100             endpoint = sendreq->req_endpoint;
 101             send_succedded = false;
 102             for(j = 0; j < (int)mca_bml_base_btl_array_get_size(&endpoint->btl_eager); j++) {
 103                 mca_bml_base_btl_t* bml_btl;
 104                 int rc;
 105 
 106                 /* select a btl */
 107                 bml_btl = mca_bml_base_btl_array_get_next(&endpoint->btl_eager);
 108                 rc = mca_pml_ob1_send_request_start_btl(sendreq, bml_btl);
 109                 if( OPAL_LIKELY(OMPI_SUCCESS == rc) ) {
 110                     send_succedded = true;
 111                     completed_requests++;
 112                     break;
 113                 }
 114             }
 115             if( false == send_succedded ) {
 116                 add_request_to_send_pending(sendreq, MCA_PML_OB1_SEND_PENDING_START, true);
 117             }
 118         }
 119     }
 120 
 121     if( 0 != completed_requests ) {
 122         j = OPAL_ATOMIC_ADD_FETCH32(&mca_pml_ob1_progress_needed, -completed_requests);
 123         if( 0 == j ) {
 124             opal_progress_unregister(mca_pml_ob1_progress);
 125         }
 126     }
 127 
 128     return completed_requests;
 129 }

/* [<][>][^][v][top][bottom][index][help] */