Exemplo n.º 1
0
static void _XMP_refect_wait_tca(_XMP_array_t *adesc)
{
  int array_dim = adesc->dim;
  tcaHandle* h = (tcaHandle*)adesc->tca_handle;
  
  for(int i=0;i<array_dim;i++){
    _XMP_array_info_t *ai = &(adesc->info[i]);
    if(ai->shadow_type == _XMP_N_SHADOW_NONE)
      continue;
    int lo_rank = ai->reflect_acc_sched->lo_rank;
    int hi_rank = ai->reflect_acc_sched->hi_rank;
    
#if 0
    if(lo_rank != -1)
      printf("[%d] lo wait from %d\n", _XMP_world_rank, lo_rank);
    if(hi_rank != -1)
      printf("[%d] hi wait from %d\n", _XMP_world_rank, hi_rank);
#endif

    if(lo_rank != -1)
      tcaWaitDMARecvDesc(&h[lo_rank], adesc->wait_slot, adesc->wait_tag);

    if(hi_rank != -1)
      tcaWaitDMARecvDesc(&h[hi_rank], adesc->wait_slot, adesc->wait_tag);

  }
}
static bool _XMP_tca_ring_buf_recv_nowait(tca_ring_buf_t *ring_buf, packet_t *packet)
{
  psn_t local_recv_psn = ring_buf->psn_pairs[1]; //1: local_recv

  //wait until (remote_send_psn > local_recv_psn) become true
  volatile psn_t* remote_send_psn_p = &(ring_buf->psn_pairs[2]); //2: remote_send
  if(*remote_send_psn_p <= local_recv_psn){
    return false;
  }    

  //copy recved data
  int buf_pos = local_recv_psn % RING_SIZE;
  *packet = ring_buf->recv_buffer[buf_pos];

  //fprintf(stderr, "recv: psn=%ull, tag=%d, data=%d\n", local_recv_psn, *tag, *data);

  //update local_recv_psn
  ring_buf->psn_pairs[1] = ++local_recv_psn;

  if(local_recv_psn - ring_buf->last_send_local_recv_psn >= (RING_SIZE/2)){
    _XMP_tca_lock();
    //send local psn pair
    const int psn_wait_slot = _wait_slot_offset + RING_SIZE;
    ring_buf->last_send_local_recv_psn = ring_buf->psn_pairs[1];
    TCA_CHECK(tcaDescSet(ring_buf->psn_desc, _dmac_channel));
    TCA_CHECK(tcaStartDMADesc(_dmac_channel));
    TCA_CHECK(tcaWaitDMARecvDesc(&(ring_buf->local_psn_pairs_handle), psn_wait_slot, _psn_wait_tag));
    TCA_CHECK(tcaWaitDMAC(_dmac_channel)); //important
    _XMP_tca_unlock();
  }

  return true;
}
static void _XMP_tca_ring_buf_recv(tca_ring_buf_t *ring_buf, int *tag, int *data)
{
  psn_t local_recv_psn = ring_buf->psn_pairs[1]; //1: local_recv
  int buf_pos = local_recv_psn % RING_SIZE;

  _XMP_tca_lock();

#ifdef _USE_NOTIFY_TO_WAIT_PACKET
  //wait notify for recv_buf
  const int buf_wait_slot = _wait_slot_offset + buf_pos;
  TCA_CHECK(tcaWaitDMARecvDesc(&(ring_buf->remote_psn_pairs_handle), buf_wait_slot, _packet_wait_tag));
#else
  //wait until (remote_send_psn > local_recv_psn) become true
  volatile psn_t* remote_send_psn_p = &(ring_buf->psn_pairs[2]); //2: remote_send
  while(*remote_send_psn_p <= local_recv_psn){
    ++spin_wait_count;
    _mm_pause();
  }
#endif

  //copy recved data
  *tag = ring_buf->recv_buffer[buf_pos].tag;
  *data = ring_buf->recv_buffer[buf_pos].data;

  //fprintf(stderr, "recv: psn=%ull, tag=%d, data=%d\n", local_recv_psn, *tag, *data);

  //update local_recv_psn
  ring_buf->psn_pairs[1] = ++local_recv_psn;

  if(local_recv_psn - ring_buf->last_send_local_recv_psn >= (RING_SIZE/2)){
    //send local psn pair
    const int psn_wait_slot = _wait_slot_offset + RING_SIZE;
    ring_buf->last_send_local_recv_psn = ring_buf->psn_pairs[1];
    TCA_CHECK(tcaDescSet(ring_buf->psn_desc, _dmac_channel));
    TCA_CHECK(tcaStartDMADesc(_dmac_channel));
    TCA_CHECK(tcaWaitDMARecvDesc(&(ring_buf->local_psn_pairs_handle), psn_wait_slot, _psn_wait_tag));
    TCA_CHECK(tcaWaitDMAC(_dmac_channel)); //important
  }

  //printf("psns: %llu, %llu, %llu, %llu\n", ring_buf->psn_pairs[0],ring_buf->psn_pairs[1],ring_buf->psn_pairs[2],ring_buf->psn_pairs[3]);
  _XMP_tca_unlock();
}
static void _XMP_tca_ring_buf_send(tca_ring_buf_t *ring_buf, const int tag, const int data) //postの場合 tag=post_req, packet=post_tag
{
  volatile psn_t *r_recv_psn = &(ring_buf->psn_pairs[3]);
  const unsigned long long local_send_psn = ring_buf->psn_pairs[0]; //0: local_send

  //fprintf(stderr,"send start (tag=%d, data=%d, psn=%llu)\n", tag, data, local_send_psn);
  _XMP_tca_lock();

  //相手のring bufferが空くまで待機
  while(local_send_psn - *r_recv_psn >= RING_SIZE){
    const int psn_wait_slot = _wait_slot_offset + RING_SIZE;
    TCA_CHECK(tcaWaitDMARecvDesc(&(ring_buf->remote_psn_pairs_handle), psn_wait_slot, _psn_wait_tag));
  }

  const int buf_pos = local_send_psn % RING_SIZE;
  const int buf_wait_slot = _wait_slot_offset + buf_pos;

  //send_bufferに値の書き込み
  ring_buf->send_buffer[buf_pos].tag = tag;
  ring_buf->send_buffer[buf_pos].data = data;
  //update local send psn
  ring_buf->psn_pairs[0] = local_send_psn + 1;
  ring_buf->last_send_local_recv_psn = ring_buf->psn_pairs[1];
  
  // set desc
  TCA_CHECK(tcaDescSet(ring_buf->buffer_desc[buf_pos], _dmac_channel));
  // start dmac
  TCA_CHECK(tcaStartDMADesc(_dmac_channel));

  // wait put locally
  TCA_CHECK(tcaWaitDMARecvDesc(&(ring_buf->local_send_buffer_handle), buf_wait_slot, _packet_wait_tag));

  //wait dmac
  TCA_CHECK(tcaWaitDMAC(_dmac_channel)); //important

  //fprintf(stderr,"send end (tag=%d, data=%d, psn=%llu)\n", tag, data, local_send_psn);

  _XMP_tca_unlock();
}