pid_t fork(void)
{
  pid_t rc;
  uint64_t time;

  VT_MEMHOOKS_OFF();

  if ( DO_TRACE(fork) )
  {
    /* mark enter function */
    time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(fork)].rid);
  }

  /* call (real) function */
  CALL_FUNC(fork, rc, ());

  if ( DO_TRACE(fork) )
  {
    /* handle fork, if succeeded */
    if ( rc != -1 )
      vt_fork(rc);

    if ( rc != 0 )
    {
      /* mark leave function */
      time = vt_pform_wtime();
      vt_exit(&time);
    }
  }
    
  VT_MEMHOOKS_ON();

  return rc;
}
/*
 * Retrieve the VampirTrace CUPTI context from the CUDA context.
 * 
 * @param cuCtx the CUDA context
 * @param ptid the active VampirTrace thread id
 * 
 * @return VampirTrace CUPTI context
 */
static vt_cupti_ctx_t* vt_cuptievt_getOrCreateCtx(CUcontext cuCtx, uint32_t ptid)
{
  vt_cupti_ctx_t *vtcuptiCtx = NULL;
  
  uint64_t time;

  /* check, if the current VampirTrace thread is enabled for GPU counters */
  if((vt_gpu_prop[ptid] & VTGPU_NO_PC) == VTGPU_NO_PC)
    return NULL;
  
  time = vt_pform_wtime();
  vt_enter(ptid, &time, vt_cuptievt_rid_init);
  
  /* retrieve a global VampirTrace CUPTI context */
  vtcuptiCtx = vt_cupti_getCreateCtx(cuCtx);
  
  /* if the event context is not available yet, then create it */
  if(NULL == vtcuptiCtx->events){
    vt_cupti_events_initContext(vtcuptiCtx);
  }
  
  time = vt_pform_wtime();
  vt_exit(ptid, &time);
  
  return vtcuptiCtx;
}
pid_t waitpid(pid_t pid, int* status, int options)
{
  pid_t rc;
  uint64_t time;

  VT_MEMHOOKS_OFF();

  if ( DO_TRACE(waitpid) )
  {
    /* mark enter function */
    time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(waitpid)].rid);
  }

  /* call (real) function */
  CALL_FUNC(waitpid, rc, (pid, status, options));

  if ( DO_TRACE(waitpid) )
  {
    /* mark leave function */
    time = vt_pform_wtime();
    vt_exit(&time);
  }

  VT_MEMHOOKS_ON();

  return rc;
}
pid_t wait(WAIT_STATUS_TYPE status)
{
  pid_t rc;
  uint64_t time;

  VT_MEMHOOKS_OFF();

  if ( DO_TRACE(wait) )
  {
    /* mark enter function */
    time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(wait)].rid);
  }

  /* call (real) function */
  CALL_FUNC(wait, rc, (status));

  if ( DO_TRACE(wait) )
  {
    /* mark leave function */
    time = vt_pform_wtime();
    vt_exit(&time);
  }

  VT_MEMHOOKS_ON();

  return rc;
}
int system(const char* string)
{
  int rc;
  uint64_t time;

  VT_MEMHOOKS_OFF();

  if ( DO_TRACE(system) )
  {
    /* mark enter function */
    time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(system)].rid);
  }

  /* call (real) function */
  CALL_FUNC(system, rc, (string));

  if ( DO_TRACE(system) )
  {
    /* mark leave function */
    time = vt_pform_wtime();
    vt_exit(&time);
  }

  VT_MEMHOOKS_ON();

  return rc;
}
VT_DECLDEF(int VT_pthread_create__(pthread_t* thread,
                                   const pthread_attr_t* attr,
                                   void *(*start_routine)(void*), void* arg))
{
  int rc;
  uint64_t time;
  struct vt_pthread_pack_struct* pack;

  if (vt_init)
  {
    vt_init = 0;
    vt_open();
  }

  time = vt_pform_wtime();
  vt_enter(VT_CURRENT_THREAD, &time, vt_pthread_regid[VT__PTHREAD_CREATE]);

  pack = (struct vt_pthread_pack_struct*)malloc(
           sizeof(struct vt_pthread_pack_struct));
  if (pack == NULL)
    vt_error();

  pack->start_routine = start_routine;
  pack->arg = arg;
  pack->ptid = VTThrd_getThreadId();

  rc = pthread_create(thread, attr, vt_pthread_function, (void*)pack);

  time = vt_pform_wtime();
  vt_exit(VT_CURRENT_THREAD, &time);

  return rc;
}
Beispiel #7
0
static void esync_master(VT_MPI_INT slave, MPI_Comm comm, VT_MPI_INT masterid)
{
  int i;
   
  uint64_t tsend, trecv, tslave;
  uint64_t t1, t2, t3, t4;
   
  MPI_Status stat;
  MPI_Request req;
  Sync_TsPerPhase* temp;
   
  /* exchange LOOP_COUNT ping pong messages with the communication partner */
   
  t1 = vt_pform_wtime();
  PMPI_Isend( &t1, 1, MPI_LONG_LONG_INT, slave, 0, comm, &req );
  PMPI_Recv( &t2, 1, MPI_LONG_LONG_INT, slave, 0, comm, &stat );
  t4 = vt_pform_wtime();
  t3 = t2;
  PMPI_Waitall( 1, &req, &stat );
   
  for( i = 1; i < LOOP_COUNT; i++ )
  {
    tsend = vt_pform_wtime();
      
    /* message exchange */

    PMPI_Isend(&tsend, 1, MPI_LONG_LONG_INT, slave, i, comm, &req);
    PMPI_Recv(&tslave, 1, MPI_LONG_LONG_INT, slave, i, comm, &stat);
    trecv = vt_pform_wtime();
      
    PMPI_Waitall(1, &req, &stat);

    /* select timestamps with minimum message delay in each direction */

    if ( ( (int64_t)tslave - (int64_t)tsend ) < ( (int64_t)t2 - (int64_t)t1 ) )
    {
      t1 = tsend;
      t2 = tslave;
    }
    if ( ( (int64_t)trecv - (int64_t)tslave ) < ( (int64_t)t4 - (int64_t)t3 ) )
    {
      t3 = tslave;
      t4 = trecv;
    }
  }

  /* save synchronization measurement data into internal data structure */

  temp = (Sync_TsPerPhase*)malloc(sizeof(Sync_TsPerPhase));
  if (!temp) vt_error();
  temp->id1  = masterid;
  temp->id2  = slave;
  temp->t1   = t1;
  temp->t2   = t2;
  temp->t3   = t3;
  temp->t4   = t4;
  temp->next = SyncTsPerRunLast->sync_phase;
  SyncTsPerRunLast->sync_phase = temp;
}
Beispiel #8
0
void POMP_Set_nest_lock(omp_nest_lock_t *s) {
  if ( IS_POMP_TRACE_ON ) {
    uint64_t time;
    time = vt_pform_wtime();
    vt_enter(VT_CURRENT_THREAD, &time, vt_omp_regid[VT__OMP_SET_NEST_LOCK]);
    omp_set_nest_lock(s);
    time = vt_pform_wtime();
    vt_exit(VT_CURRENT_THREAD, &time);
  } else {
    omp_set_nest_lock(s);
  }
}
Beispiel #9
0
void POMP_Destroy_lock(omp_lock_t *s) {
  if ( IS_POMP_TRACE_ON ) {
    uint64_t time;
    time = vt_pform_wtime();
    vt_enter(VT_CURRENT_THREAD, &time, vt_omp_regid[VT__OMP_DESTROY_LOCK]);
    omp_destroy_lock(s);
    time = vt_pform_wtime();
    vt_exit(VT_CURRENT_THREAD, &time);
  } else {
    omp_destroy_lock(s);
  }
}
Beispiel #10
0
void POMP_Unset_nest_lock(omp_nest_lock_t *s) {
  if ( IS_POMP_TRACE_ON ) {
    uint64_t time = vt_pform_wtime();
    vt_enter(&time, vt_omp_regid[VT__OMP_UNSET_NEST_LOCK]);
    omp_unset_nest_lock(s);
    time = vt_pform_wtime();
    vt_omp_rlock(&time, vt_lock_id(s));
    vt_exit(&time);
  } else {
    omp_unset_nest_lock(s);
  }
}
Beispiel #11
0
DEF_FPOMP_FUNC(void POMP_Unset_nest_lock_f(omp_nest_lock_t *s)) {
  if ( IS_POMP_TRACE_ON ) {
    uint64_t time = vt_pform_wtime();
    vt_enter(&time, vt_omp_regid[VT__OMP_UNSET_NEST_LOCK]);
    omp_unset_nest_lock(s);
    time = vt_pform_wtime();
    vt_omp_rlock(&time, vt_lock_id(s));
    vt_exit(&time);
  } else {
    omp_unset_nest_lock(s);
  }
} VT_GENERATE_F77_BINDINGS(pomp_unset_nest_lock, POMP_UNSET_NEST_LOCK,
Beispiel #12
0
VT_DECLDEF(void POMP_Unset_nest_lock_f(omp_nest_lock_t *s)) {
  if ( IS_POMP_TRACE_ON ) {
    uint64_t time;
    time = vt_pform_wtime();
    vt_enter(VT_CURRENT_THREAD, &time, vt_omp_regid[VT__OMP_UNSET_NEST_LOCK]);
    omp_unset_nest_lock(s);
    time = vt_pform_wtime();
    vt_exit(VT_CURRENT_THREAD, &time);
  } else {
    omp_unset_nest_lock(s);
  }
} VT_GENERATE_F77_BINDINGS(pomp_unset_nest_lock, POMP_UNSET_NEST_LOCK,
Beispiel #13
0
void POMP_Destroy_nest_lock(omp_nest_lock_t *s) {
  if ( IS_POMP_TRACE_ON ) {
    uint64_t time = vt_pform_wtime();
    vt_enter(&time, vt_omp_regid[VT__OMP_DESTROY_NEST_LOCK]);
    omp_destroy_nest_lock(s);
    vt_lock_destroy(s);
    time = vt_pform_wtime();
    vt_exit(&time);
  } else {
    omp_destroy_nest_lock(s);
    vt_lock_destroy(s);
  }
}
Beispiel #14
0
DEF_FPOMP_FUNC(void POMP_Destroy_lock_f(omp_lock_t *s)) {
  if ( IS_POMP_TRACE_ON ) {
    uint64_t time = vt_pform_wtime();
    vt_enter(&time, vt_omp_regid[VT__OMP_DESTROY_LOCK]);
    omp_destroy_lock(s);
    vt_lock_destroy(s);
    time = vt_pform_wtime();
    vt_exit(&time);
  } else {
    omp_destroy_lock(s);
    vt_lock_destroy(s);
  }
} VT_GENERATE_F77_BINDINGS(pomp_destroy_lock, POMP_DESTROY_LOCK,
Beispiel #15
0
void POMP_Init_nest_lock(omp_nest_lock_t *s) {
  if ( IS_POMP_TRACE_ON ) {
    uint64_t time = vt_pform_wtime();
    vt_enter(&time, vt_omp_regid[VT__OMP_INIT_NEST_LOCK]);
    omp_init_nest_lock(s);
    vt_lock_init(s);
    time = vt_pform_wtime();
    vt_exit(&time);
  } else {
    omp_init_nest_lock(s);
    vt_lock_init(s);
  }
}
Beispiel #16
0
int POMP_Test_nest_lock(omp_nest_lock_t *s) {
  if ( IS_POMP_TRACE_ON ) {
    int result;
    uint64_t time;
    time = vt_pform_wtime();
    vt_enter(VT_CURRENT_THREAD, &time, vt_omp_regid[VT__OMP_TEST_NEST_LOCK]);
    result = omp_test_nest_lock(s);
    time = vt_pform_wtime();
    vt_exit(VT_CURRENT_THREAD, &time);
    return result;
  } else {
    return omp_test_nest_lock(s);
  }
}
Beispiel #17
0
void POMP_Init_lock(omp_lock_t *s) {
  if ( !pomp_initialized ) POMP_Init();

  if ( IS_POMP_TRACE_ON ) {
    uint64_t time;
    time = vt_pform_wtime();
    vt_enter(VT_CURRENT_THREAD, &time, vt_omp_regid[VT__OMP_INIT_LOCK]);
    omp_init_lock(s);
    time = vt_pform_wtime();
    vt_exit(VT_CURRENT_THREAD, &time);
  } else {
    omp_init_lock(s);
  }
}
Beispiel #18
0
VT_DECLDEF(void POMP_Init_lock_f(omp_lock_t *s)) {
  if ( !pomp_initialized ) POMP_Init();

  if ( IS_POMP_TRACE_ON ) {
    uint64_t time;
    time = vt_pform_wtime();
    vt_enter(VT_CURRENT_THREAD, &time, vt_omp_regid[VT__OMP_INIT_LOCK]);
    omp_init_lock(s);
    time = vt_pform_wtime();
    vt_exit(VT_CURRENT_THREAD, &time);
  } else {
    omp_init_lock(s);
  }
} VT_GENERATE_F77_BINDINGS(pomp_init_lock, POMP_INIT_LOCK,
Beispiel #19
0
VT_DECLDEF(int POMP_Test_nest_lock_f(omp_nest_lock_t *s)) {
  if ( IS_POMP_TRACE_ON ) {
    int result;
    uint64_t time;
    time = vt_pform_wtime();
    vt_enter(VT_CURRENT_THREAD, &time, vt_omp_regid[VT__OMP_TEST_NEST_LOCK]);
    result = omp_test_nest_lock(s);
    time = vt_pform_wtime();
    vt_exit(VT_CURRENT_THREAD, &time);
    return result;
  } else {
    return omp_test_nest_lock(s);
  }
} VT_GENERATE_F77_BINDINGS(pomp_test_nest_lock, POMP_TEST_NEST_LOCK,
void phat_enter(char *str, int *id) {
  uint64_t time;

  /* -- if not yet initialized, initialize VampirTrace -- */
  if ( phat_init ) {
    uint32_t main_id;
    VT_MEMHOOKS_OFF();
    phat_init = 0;
    vt_open();

    main_id = register_region("main");
    time = vt_pform_wtime();
    vt_enter(&time, main_id);
    VT_MEMHOOKS_ON();
  }

  /* -- if VampirTrace already finalized, return -- */
  if ( !vt_is_alive ) return;

  /* -- ignore SUN OMP runtime functions -- */
  if ( strchr(str, '$') != NULL ) return;

  VT_MEMHOOKS_OFF();

  time = vt_pform_wtime();

  /* -- get region identifier -- */
  if ( *id == -1 ) {
    /* -- region entered the first time, register region -- */
#   if defined (VT_OMPI) || defined (VT_OMP)
    if (omp_in_parallel()) {
#     pragma omp critical (vt_comp_phat_1)
      {
        if ( (*id = hash_get((long) str)) == VT_NO_ID ) {
          *id = register_region(str);
        }
      }
    } else {
      *id = register_region(str);
    }
#   else
    *id = register_region(str);
#   endif
  }

  /* -- write enter record -- */
  vt_enter(&time, *id);

  VT_MEMHOOKS_ON();
}
Beispiel #21
0
void* vt_malloc_hook(size_t size, const void* caller)
{
  void* result;
  uint64_t bytes;
  uint64_t time;
  uint8_t was_recorded;

  VT_MEMHOOKS_OFF(); /* restore original hooks */

  time = vt_pform_wtime();
  was_recorded = vt_enter(VT_CURRENT_THREAD, &time,
                          memhook_regid[MEMHOOK_REG_MALLOC]);

  result = malloc(size); /* call recursively */

  /* get total allocated memory */
  if ( result != NULL )
  {
    bytes = ( ~ (uint64_t) 3 ) & (uint64_t) *( (size_t*) ( (char*)result - SIZEOF_VOIDP ) );
  }
  else
  {
    bytes = 0;
  }

  /* update counter value */
  memalloc_val += bytes;

  time = vt_pform_wtime();

  if ( was_recorded && bytes > 0 )
  {
    /* write marker, if desired */
    if( memalloc_marker )
    {
      vt_marker(VT_CURRENT_THREAD, &time, memalloc_mid[MEMHOOK_MARK_ALLOC],
                "Allocated %llu Bytes", (unsigned long long)bytes);
    }

    /* write counter value */
    vt_count(VT_CURRENT_THREAD, &time, memalloc_cid, memalloc_val);
  }

  vt_exit(VT_CURRENT_THREAD, &time);

  VT_MEMHOOKS_ON(); /* restore our own hooks */

  return result;
}
Beispiel #22
0
DEF_FPOMP_FUNC(int POMP_Test_nest_lock_f(omp_nest_lock_t *s)) {
  if ( IS_POMP_TRACE_ON ) {
    int result;
    uint64_t time = vt_pform_wtime();

    vt_enter(&time, vt_omp_regid[VT__OMP_TEST_NEST_LOCK]);
    result = omp_test_nest_lock(s);
    time = vt_pform_wtime();
    if (result) vt_omp_alock(&time, vt_lock_id(s));
    vt_exit(&time);
    return result;
  } else {
    return omp_test_nest_lock(s);
  }
} VT_GENERATE_F77_BINDINGS(pomp_test_nest_lock, POMP_TEST_NEST_LOCK,
Beispiel #23
0
int POMP_Test_nest_lock(omp_nest_lock_t *s) {
  if ( IS_POMP_TRACE_ON ) {
    int result;
    uint64_t time = vt_pform_wtime();

    vt_enter(&time, vt_omp_regid[VT__OMP_TEST_NEST_LOCK]);
    result = omp_test_nest_lock(s);
    time = vt_pform_wtime();
    if (result) vt_omp_alock(&time, vt_lock_id(s));
    vt_exit(&time);
    return result;
  } else {
    return omp_test_nest_lock(s);
  }
}
Beispiel #24
0
void vt_free_hook(void* ptr, const void* caller)
{
  uint64_t bytes;
  uint64_t time;
  uint8_t was_recorded;

  VT_MEMHOOKS_OFF(); /* restore original hooks */

  time = vt_pform_wtime();
  was_recorded = vt_enter(VT_CURRENT_THREAD, &time,
                          memhook_regid[MEMHOOK_REG_FREE]);

  if ( NULL != ptr )
  {
    bytes = ( ~ (uint64_t) 3 ) & (uint64_t) *( (size_t*) ( (char*)ptr - SIZEOF_VOIDP ) );
  }
  else
  {
    bytes = 0;
  }

  free(ptr); /* call recursively */

  /* update counter value */
  if ( bytes <= memalloc_val )
    memalloc_val -= bytes;
  else
    memalloc_val = 0;

  time = vt_pform_wtime();

  if ( was_recorded && bytes > 0 )
  {
    /* write marker, if desired */
    if( memalloc_marker )
    {
      vt_marker(VT_CURRENT_THREAD, &time, memalloc_mid[MEMHOOK_MARK_FREE],
                "Freed %llu Bytes", (unsigned long long)bytes);
    }

    /* write counter value */
    vt_count(VT_CURRENT_THREAD, &time, memalloc_cid, memalloc_val);
  }

  vt_exit(VT_CURRENT_THREAD, &time);

  VT_MEMHOOKS_ON(); /* restore our own hooks */
}
void VT_User_start__(const char* name, const char* file, int lno)
{
  uint32_t rid;
  uint64_t time;

  VT_INIT;

  VT_SUSPEND_MALLOC_TRACING(VT_CURRENT_THREAD);

  time = vt_pform_wtime();

  /* -- get region identifier by address -- */
  if ( (rid = hash_get_addr((unsigned long)name)) == VT_NO_ID )
  {
    /* -- region entered the first time, register region -- */
#if (defined(VT_MT) || defined(VT_HYB))
    VTTHRD_LOCK_IDS();
    if ( (rid = hash_get_addr((unsigned long)name)) == VT_NO_ID )
      rid = register_region((unsigned long)name, name, file, lno);
    VTTHRD_UNLOCK_IDS();
#else /* VT_MT || VT_HYB */
    rid = register_region((unsigned long)name, name, file, lno);
#endif /* VT_MT || VT_HYB */
  }

  /* -- write enter record -- */
  vt_enter(VT_CURRENT_THREAD, &time, rid);

  VT_RESUME_MALLOC_TRACING(VT_CURRENT_THREAD);
}
VT_DECLDEF(void __profile_loop(struct profile_gen_struct* d))
{
  uint64_t time;

  /* -- if VampirTrace already finalized, return -- */
  if ( !vt_is_alive ) return;

  VT_MEMHOOKS_OFF();

  time = vt_pform_wtime();

  /* -- get region identifier -- */
  if ( d->data == NULL )
  {
    /* -- loop entered the first time, register region -- */
#if (defined(VT_MT) || defined(VT_HYB))
    VTTHRD_LOCK_IDS();
    if ( d->data == NULL )
      register_region(d, VT_LOOP);
    VTTHRD_UNLOCK_IDS();
#else /* VT_MT || VT_HYB */
    register_region(d, VT_LOOP);
#endif /* VT_MT || VT_HYB */
  }

  /* -- write enter record -- */
  vt_enter(&time, *((uint32_t*)(d->data)));

  VT_MEMHOOKS_ON();
}
void VT_User_start__(const char* name, const char *file, int lno) {
  uint32_t rid;
  uint64_t time;

  /* -- if not yet initialized, initialize VampirTrace -- */
  if ( vt_init ) {
    VT_MEMHOOKS_OFF();
    vt_init = 0;
    vt_open();
    VT_MEMHOOKS_ON();
  }

  VT_MEMHOOKS_OFF();

  time = vt_pform_wtime();

  /* -- get region identifier -- */
  if ( (rid = hash_get((unsigned long) name)) == VT_NO_ID ) {
    /* -- region entered the first time, register region -- */
#if (defined(VT_MT) || defined(VT_HYB))
    VTTHRD_LOCK_IDS();
    if ( (rid = hash_get((unsigned long) name)) == VT_NO_ID )
      rid = register_region(name, 0, file, lno);
    VTTHRD_UNLOCK_IDS();
#else /* VT_MT || VT_HYB */
    rid = register_region(name, 0, file, lno);
#endif /* VT_MT || VT_HYB */
  }

  /* -- write enter record -- */
  vt_enter(&time, rid);

  VT_MEMHOOKS_ON();
}
Beispiel #28
0
void POMP_Parallel_end(struct ompregdescr* r) {
  if ( IS_POMP_TRACE_ON ) {
    uint64_t time = vt_pform_wtime();
    vt_exit(&time);
    vt_omp_parallel_end();
  }
}
/*
 * Create a VampirTrace CUPTI activity context.
 * 
 * @return pointer to created VampirTrace CUPTI Activity context
 */
static vt_cupti_activity_t* vt_cuptiact_createCtxActivity(CUcontext cuCtx)
{
  vt_cupti_activity_t* vtCtxAct = NULL;
  
  /* create new context, as it is not listed */
  vtCtxAct = (vt_cupti_activity_t *)malloc(sizeof(vt_cupti_activity_t));
  if(vtCtxAct == NULL) 
    vt_error_msg("[CUPTI Activity] Could not allocate memory for activity context!");
  vtCtxAct->strmList = NULL;
  vtCtxAct->gpuMemAllocated = 0;
  vtCtxAct->gpuMemList = NULL;
  vtCtxAct->buffer = NULL;
  vtCtxAct->vtLastGPUTime = vt_gpu_init_time;
  vtCtxAct->gpuIdleOn = 1;
  
  /* 
   * Get time synchronization factor between host and GPU time for measurement 
   * interval 
   */
  {
    VT_CUPTI_CALL(cuptiGetTimestamp(&(vtCtxAct->sync.gpuStart)), "cuptiGetTimestamp");
    vtCtxAct->sync.hostStart = vt_pform_wtime();
  }
  
    /* set default CUPTI stream ID (needed for memory usage and idle tracing) */
  VT_CUPTI_CALL(cuptiGetStreamId(cuCtx, NULL, &(vtCtxAct->defaultStrmID)), 
                                 "cuptiGetStreamId");
  
  return vtCtxAct;
}
Beispiel #30
0
void POMP_Parallel_begin(struct ompregdescr* r) {
  if ( IS_POMP_TRACE_ON ) {
    struct VTRegDescr* data = (struct VTRegDescr*)(r->data);
    uint64_t time = vt_pform_wtime();
    vt_omp_parallel_begin();
    vt_enter(&time, data->rid);
  }
}