void vt_plugin_cntr_thread_exit(VTThrd * thrd) {
  uint32_t i, j;

  struct vt_plugin_cntr_defines * defines =
      (struct vt_plugin_cntr_defines *) thrd->plugin_cntr_defines;

  vt_cntl_msg(3, "Process %i Thread %s-%s exits plugin counters ...",
      vt_my_ptrace, thrd->name, thrd->name_suffix);

  /* make sure that we can process */
  if (defines == NULL)
    return;

  vt_plugin_cntr_thread_disable_counters(thrd);
  /* free per thread resources */
  if (defines->counters != NULL) {
    for (i = 0; i < VT_PLUGIN_CNTR_SYNCH_TYPE_MAX; i++) {
      if (defines->counters[i] != NULL) {
        if (defines->size_of_counters != NULL) {
          for (j = 0; j < defines->size_of_counters[i]; j++) {
#if (defined(VT_MT) || defined (VT_HYB) || defined(VT_JAVA))
            if (defines->counters[i][j].callback_mutex!=NULL)
              VTThrd_lock((VTThrdMutex **) &defines->counters[i][j].callback_mutex);
            if (defines->counters[i][j].callback_values != NULL) {
              free(defines->counters[i][j].callback_values);
              defines->counters[i][j].callback_values = NULL;
              vt_trace_off(thrd->tid, 0, 1);
            }
            if (defines->counters[i][j].callback_mutex != NULL) {
              VTThrd_unlock((VTThrdMutex **) &defines->counters[i][j].callback_mutex);
              VTThrd_deleteMutex((VTThrdMutex **) &(defines->counters[i][j].callback_mutex));
            }
#endif /* VT_MT || VT_HYB || VT_JAVA */
          }
        }
        free(defines->counters[i]);
      }
    }
    free(defines->counters);
  }
  if (defines->size_of_counters != NULL)
    free(defines->size_of_counters);
  free(defines);

  vt_cntl_msg(3, "Process %i Thread %s-%s exits plugin counters ... done",
      vt_my_ptrace, thrd->name, thrd->name_suffix);
}
Beispiel #2
0
int vt_env_stat_props()
{
  static int propflags = 0;
  char* tmp;

  if (propflags == 0)
    {
      tmp = getenv("VT_STAT_PROPS");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          char tmpbuf[128];
          char* p;
          char* tk;
          int dc;

          vt_cntl_msg(2, "VT_STAT_PROPS=%s", tmp);

          p = tmpbuf;
          strncpy(tmpbuf, tmp, 127);
          tmpbuf[127] = '\0';
          while( *p ) { *p = tolower(*p); p++; }

          if (strcmp( tmpbuf, "all" ) == 0)
            {
              propflags = (VT_SUM_PROP_FUNC | VT_SUM_PROP_MSG | VT_SUM_PROP_COLLOP);
            }
          else
            {
              tk = strtok(tmpbuf, ":");
              dc = 0;
              propflags = 0;
              do {
                if (dc <= 2 &&
                    (strcmp( tk, "func" ) == 0))
                  propflags |= VT_SUM_PROP_FUNC;
                else if(dc <= 2 &&
                        (strcmp( tk, "msg" ) == 0))
                  propflags |= VT_SUM_PROP_MSG;
                else if(dc <= 2 &&
                        (strcmp( tk, "collop" ) == 0))
                  propflags |= VT_SUM_PROP_COLLOP;
/*              else if(dc <= 3 &&
                        (strcmp( tk, "fileop" ) == 0))
                        propflags |= VT_SUM_PROP_FILEOP; */
                else
                  vt_error_msg("VT_STAT_PROPS not properly set");
                dc++;
              } while((tk = strtok(0, ":")));
            }
        }
      else
        {
          /* propflags =
               (VT_SUM_PROP_FUNC | VT_SUM_PROP_MSG | VT_SUM_PROP_COLLOP | VT_SUM_PROP_FILEOP); */
          propflags = (VT_SUM_PROP_FUNC | VT_SUM_PROP_MSG | VT_SUM_PROP_COLLOP);
        }
    }
  return propflags;
}
/*
 * Finalize the VampirTrace CUPTI context and free all memory allocated with it.
 * 
 * @param vtCtx pointer to the VampirTrace CUPTI context
 */
void vt_cupti_finalizeCtx(vt_cupti_ctx_t *vtCtx)
{
  if(vtCtx == NULL)
    return;
  
  /* write exit event for GPU idle time */
  if(vt_gpu_trace_idle > 0 && vtCtx->strmList != NULL 
#if defined(VT_CUPTI_ACTIVITY)
     && vtCtx->activity != NULL && vtCtx->activity->gpuIdleOn == 1
#endif
    ){
    uint64_t idle_end = vt_pform_wtime();
    
    /*vt_warning("IDLEexit: %llu (%d)", idle_end, vtCtx->strmList->vtThrdID);*/
    vt_exit(vtCtx->strmList->vtThrdID, &idle_end);
  }
  
  /* cleanup stream list */
  while(vtCtx->strmList != NULL){
    vt_cupti_strm_t *vtStrm = vtCtx->strmList;
    
    vtCtx->strmList = vtCtx->strmList->next;
    
    free(vtStrm);
    vtStrm = NULL;
  }
  
  /* free CUDA malloc entries, if user application has memory leaks */
  while(vtCtx->gpuMemList != NULL){
    vt_cupti_gpumem_t *vtMem =  vtCtx->gpuMemList;
    
    if(vt_gpu_trace_memusage > 1)
      vt_cntl_msg(1, "[CUPTI] Free of %d bytes GPU memory missing!", 
                     vtMem->size);
    
    vtCtx->gpuMemList = vtMem->next;
    free(vtMem);
    vtMem = NULL;
  }
  
#if defined(VT_CUPTI_ACTIVITY)
  if(vtCtx->activity != NULL)
    free(vtCtx->activity);
#endif

#if (defined(VT_CUPTI_CALLBACKS) && !defined(VT_CUPTI_ACTIVITY))
  if(vtCtx->callbacks != NULL)
    free(vtCtx->callbacks);
#endif
  
#if defined(VT_CUPTI_EVENTS)
  if(vtCtx->events != NULL)
    free(vtCtx->events);
#endif
  
  free(vtCtx);
  vtCtx = NULL;
}
static void vt_cuptievt_start(vt_cupti_events_t *vtcuptiEvtCtx)
{
  CUptiResult cuptiErr = CUPTI_SUCCESS;
  vt_cupti_evtgrp_t *vtcuptiGrp = NULL;
  vt_cupti_evtgrp_t *lastGrp = NULL;

  /* start gathering counter values, if context was successfully initialized */
  if(NULL == vtcuptiEvtCtx){
    /* no performance counters for this thread available */
    VT_CHECK_THREAD;
    vt_gpu_prop[VT_MY_THREAD] |= VTGPU_NO_PC;
    vt_cntl_msg(2, "[CUPTI Events] Context not initialized!");
    return;
  }

  /* start all groups */
  vtcuptiGrp = vtcuptiEvtCtx->vtGrpList;
  lastGrp = vtcuptiEvtCtx->vtGrpList;
  while(vtcuptiGrp != NULL){
    cuptiErr = cuptiEventGroupEnable(vtcuptiGrp->evtGrp);
    
    /* if the event group could not be enabled, remove it */
    if(cuptiErr != CUPTI_SUCCESS){
      size_t i;
      vt_cupti_evtgrp_t *freeGrp = vtcuptiGrp;
      size_t valueSize = 32;
      char name[32];

      vtcuptiGrp = vtcuptiGrp->next;

      /* give user information about the group, which cannot be enabled */
      for(i = 0; i < freeGrp->evtNum; i++){
        VTCUPTIEVENTGETATTRIBUTE(vtcuptiEvtCtx->vtDevCap->cuDev,
                                 *(freeGrp->cuptiEvtIDs)+i,
                                 CUPTI_EVENT_ATTR_NAME,
                                 &valueSize, (char*)name);
        vt_warning("[CUPTI Events] Event '%s' (%d) cannot be enabled",
                   name, *(freeGrp->cuptiEvtIDs)+i);
      }

      /* group is first element in linked list */
      if(vtcuptiEvtCtx->vtGrpList == freeGrp){
        vtcuptiEvtCtx->vtGrpList = vtcuptiEvtCtx->vtGrpList->next;
      }else{/* has to be at least the second group in linked list */
        lastGrp->next = freeGrp->next;
      }

      free(freeGrp);
      freeGrp = NULL;
    }else{
      vtcuptiGrp->enabled = 1;
      lastGrp= vtcuptiGrp;
      vtcuptiGrp = vtcuptiGrp->next;
    }
  }
  
}
/*
 * Initialize the CUPTI events data of the given VampirTrace CUPTI context.
 * 
 * @param vtCtx pointer to the VampirTrace CUPTI context
 */
void vt_cupti_events_initContext(vt_cupti_ctx_t *vtcuptiCtx)
{
  vt_cupti_events_t *vtcuptiEvtCtx = NULL;
  
  vt_cntl_msg(2, "[CUPTI Events] Initializing VampirTrace CUPTI events context");

  /* get a pointer to eventIDArray */
  {
    CUresult cuErr = CUDA_SUCCESS;
    int dev_major, dev_minor;
    vt_cupti_device_t *cuptiDev;

    /* TODO: do not trace this driver API function call */
    cuErr = cuDeviceComputeCapability(&dev_major, &dev_minor, vtcuptiCtx->cuDev);
    VT_CUDRV_CALL(cuErr, "cuDeviceComputeCapability");

    /* check if device capability already listed */
    VT_CUPTI_LOCK();
      cuptiDev = vtcuptievtCapList;
    VT_CUPTI_UNLOCK();
    
    cuptiDev = vt_cupti_checkMetricList(cuptiDev, dev_major, dev_minor);
    if(cuptiDev){
      /* allocate the VampirTrace CUPTI events context */
      vtcuptiEvtCtx = (vt_cupti_events_t *)malloc(sizeof(vt_cupti_events_t));
      if(vtcuptiEvtCtx == NULL)
        vt_error_msg("[CUPTI Events] malloc(sizeof(vt_cupti_events_t)) failed!");
      
      vtcuptiEvtCtx->vtDevCap = cuptiDev;
      vtcuptiEvtCtx->vtGrpList = NULL;
      vtcuptiEvtCtx->counterData = NULL;
      vtcuptiEvtCtx->cuptiEvtIDs = NULL;
      
      vtcuptiCtx->events = vtcuptiEvtCtx;
    }else{
      return;
    }
  }

  /* create and add the VampirTrace CUPTI groups to the context */
  vt_cupti_addEvtGrpsToCtx(vtcuptiCtx);

  /* allocate memory for CUPTI counter reads */
  {
    size_t allocSize = vtcuptiEvtCtx->vtGrpList->evtNum;
    
    vtcuptiEvtCtx->counterData = 
            (uint64_t *)malloc(allocSize*sizeof(uint64_t));
    vtcuptiEvtCtx->cuptiEvtIDs = 
            (CUpti_EventID *)malloc(allocSize*sizeof(CUpti_EventID));
  }
  
  vt_cuptievt_start(vtcuptiEvtCtx);
}
static void vt_cupti_addEvtGrpsToCtx(vt_cupti_ctx_t *vtcuptiCtx)
{
    CUptiResult cuptiErr = CUPTI_SUCCESS;
    vt_cupti_evtgrp_t *vtcuptiGrp = vt_cuptievt_createEvtGrp(vtcuptiCtx);
    vt_cupti_events_t *vtcuptiEvents = vtcuptiCtx->events;
    vt_cupti_evtctr_t *vtcuptiEvt = vtcuptiEvents->vtDevCap->vtcuptiEvtList;

    /* try to add all events for current context/device */
    while(vtcuptiEvt != NULL && vtcuptiGrp->evtNum < vtcuptiEvents->vtDevCap->evtNum){
      cuptiErr = cuptiEventGroupAddEvent(vtcuptiGrp->evtGrp,
                                         vtcuptiEvt->cuptiEvtID);

      /* everything is fine */
      if(cuptiErr == CUPTI_SUCCESS){
        vtcuptiGrp->cuptiEvtIDs[vtcuptiGrp->evtNum] = vtcuptiEvt->cuptiEvtID;
        vtcuptiGrp->vtCIDs[vtcuptiGrp->evtNum] = vtcuptiEvt->vtCID;
        vtcuptiGrp->evtNum++;
      }else{
        /* we can at least try to put the event in another group */

        /* too many events in this group or
           event is in different domain or device limitation*/
        if(cuptiErr == CUPTI_ERROR_MAX_LIMIT_REACHED ||
           cuptiErr == CUPTI_ERROR_NOT_COMPATIBLE){

          vt_cntl_msg(2, "[CUPTI Events] Create new event group for event %d",
                         vtcuptiEvt->cuptiEvtID);

          /* prepend last group to list, if it is not empty */
          if(vtcuptiGrp->evtNum > 0){
            vtcuptiGrp->next = vtcuptiEvents->vtGrpList;
            vtcuptiEvents->vtGrpList = vtcuptiGrp;
          }

          /* create new VampirTrace CUPTI event group */
          vtcuptiGrp = vt_cuptievt_createEvtGrp(vtcuptiCtx);

          /* try to add the same event to the just created group */
          continue;
        }

        PRINT_CUPTI_ERROR(cuptiErr, "cuptiEventGroupAddEvent");
      }

      vtcuptiEvt = vtcuptiEvt->next;
    }

    /* prepend last group to list, if it is not empty */
    if(vtcuptiGrp->evtNum > 0){
      vtcuptiGrp->next = vtcuptiEvents->vtGrpList;
      vtcuptiEvents->vtGrpList = vtcuptiGrp;
    }
}
void vt_metric_thread_init(long (*id_fn)(void))
{
  int retval;

  if ( nmetrics == 0 )
    return;

  retval = PAPI_thread_init((unsigned long (*)(void))(id_fn));
  if ( retval != PAPI_OK)
    metric_error(retval, "PAPI_thread_init");
  vt_cntl_msg(2, "PAPI thread support initialized");
}
/*
 * Finalizes CUPTI device.
 * 
 * @param ptid VampirTrace process/thread id
 * @param cleanExit 1 to cleanup CUPTI event group, otherwise 0
 */
void vt_cuptievt_finalize_device(uint8_t cleanExit){
  CUptiResult cuptiErr = CUPTI_SUCCESS;
  vt_cupti_ctx_t *vtcuptiCtx = NULL;

  vt_cntl_msg(2, "[CUPTI Events] Finalize device ... ");

  {
    CUcontext cuCtx;
    
#if (defined(CUDA_VERSION) && (CUDA_VERSION < 4000))
    VT_CUDRV_CALL(cuCtxPopCurrent(&cuCtx), "cuCtxPopCurrent");
    VT_CUDRV_CALL(cuCtxPushCurrent(cuCtx), "cuCtxPushCurrent");
#else
    VT_CUDRV_CALL(cuCtxGetCurrent(&cuCtx), "cuCtxGetCurrent");
#endif

    vtcuptiCtx = vt_cupti_removeCtx(&cuCtx);
    if(vtcuptiCtx == NULL) 
      return;
  }
  
  if(vtcuptiCtx->events == NULL)
    return;

  if(cleanExit && vt_gpu_debug != 0){
    /*uint64_t time = vt_pform_wtime();

    vt_cupti_resetCounter(vtcuptiCtx, 0, &time);*/

    /* stop CUPTI counter capturing */
    vt_cuptievt_stop(vtcuptiCtx->events);

    /* destroy all CUPTI event groups, which have been created */
    {
      vt_cupti_evtgrp_t *vtcuptiGrp = vtcuptiCtx->events->vtGrpList;

      while(vtcuptiGrp != NULL){
        cuptiErr = cuptiEventGroupRemoveAllEvents(vtcuptiGrp->evtGrp);
        VT_CUPTI_CALL(cuptiErr, "cuptiEventGroupRemoveAllEvents");

        cuptiErr = cuptiEventGroupDestroy(vtcuptiGrp->evtGrp);
        VT_CUPTI_CALL(cuptiErr, "cuptiEventGroupDestroy");

        vtcuptiGrp = vtcuptiGrp->next;
      }
    }
  }

  /* free VampirTrace CUPTI event context */
  vt_cuptievt_freeEventCtx(vtcuptiCtx->events);
}
Beispiel #9
0
/*
 * Finalizes CUPTI device.
 * 
 * @param cleanExit 1 to cleanup CUPTI event group, otherwise 0
 */
void vt_cupti_finalize_device(uint32_t ptid, uint8_t cleanExit){
  CUptiResult cuptiErr = CUPTI_SUCCESS;
  vt_cupti_ctx_t *vtcuptiCtx = NULL;

  vt_cntl_msg(2, "[CUPTI] Finalize device ... ");

  {
    CUcontext cuCtx = NULL;

    VT_SUSPEND_CUDA_TRACING(ptid);
    
#if (defined(CUDA_VERSION) && (CUDA_VERSION < 4000))
    CHECK_CU_ERROR(cuCtxPopCurrent(&cuCtx), "cuCtxPopCurrent");
    CHECK_CU_ERROR(cuCtxPushCurrent(cuCtx), "cuCtxPushCurrent");
#else
    CHECK_CU_ERROR(cuCtxGetCurrent(&cuCtx), "cuCtxGetCurrent");
#endif
    
    VT_RESUME_CUDA_TRACING(ptid);

    vtcuptiCtx = vt_cupti_takeCtxFromList(cuCtx);
    if(vtcuptiCtx == NULL) return;
  }

  if(cleanExit && vt_gpu_debug != 0){
    /*uint64_t time = vt_pform_wtime();

    vt_cupti_resetCounter(vtcuptiCtx, 0, &time);*/

    /* stop CUPTI counter capturing */
    vt_cupti_stop(vtcuptiCtx);

    /* destroy all CUPTI event groups, which have been created */
    {
      vt_cupti_grp_t *vtcuptiGrp = vtcuptiCtx->vtGrpList;

      while(vtcuptiGrp != NULL){
        cuptiErr = cuptiEventGroupRemoveAllEvents(vtcuptiGrp->evtGrp);
        CHECK_CUPTI_ERROR(cuptiErr, "cuptiEventGroupRemoveAllEvents");

        cuptiErr = cuptiEventGroupDestroy(vtcuptiGrp->evtGrp);
        CHECK_CUPTI_ERROR(cuptiErr, "cuptiEventGroupDestroy");

        vtcuptiGrp = vtcuptiGrp->next;
      }
    }
  }

  /* free VampirTrace CUPTI context */
  vt_cupti_freeCtx(vtcuptiCtx);
}
static void metricmap_free(metricmap_t* map)
{
  if (map == NULL)
    return;

  vt_cntl_msg(3, "Metricmap free (head=0x%p):", map);
  while (map != NULL) {
    metricmap_t* next = map->next;
    if (map->event_name != NULL) free(map->event_name);
    if (map->alias_name != NULL) free(map->alias_name);
    free(map);
    map = next;
  }
}
void vt_fork_waitchilds()
{
  uint32_t i;
  int status;

  if ( nchilds == 0 ) return;

  VT_SUSPEND_EXEC_TRACING(VT_CURRENT_THREAD);

  /* wait until all child processes are terminated */
  for( i = 0; i < nchilds; i++ )
  {
    vt_cntl_msg(2, "Waiting until child process %i terminated",
		(int)childv[i]);

    waitpid(childv[i], &status, 0);

    vt_cntl_msg(2, "Child process %i terminated, leaving %u",
		(int)childv[i], nchilds-i-1);
  }

  VT_RESUME_EXEC_TRACING(VT_CURRENT_THREAD);
}
Beispiel #12
0
/*
 * Retrieve the VampirTrace CUPTI context from the CUDA context.
 * 
 * @param cuCtx the CUDA context
 * @param ptid the active VampirTrace thread id
 */
static vt_cupti_ctx_t* vt_cupti_getCtx(CUcontext cuCtx, uint32_t ptid)
{
  vt_cupti_ctx_t *vtcuptiCtx = NULL;

  /* check, if there has been at least one VampirTrace CUPTI context created */
  if(vtcuptiCtxlist == NULL) vt_cupti_init();

  /* check, if the current VampirTrace thread is enabled for GPU counters */
  if((vt_gpu_prop[ptid] & VTGPU_NO_PC) == VTGPU_NO_PC)
    return NULL;

  /* check if CUDA context is listed (linear search) */
  CUPTI_LOCK();
  vtcuptiCtx = vtcuptiCtxlist;
  while(vtcuptiCtx != NULL){
    if(vtcuptiCtx->cuCtx == cuCtx){
      CUPTI_UNLOCK();
      /*vt_cntl_msg(1, "[CUPTI] host thread %d (MPI rank %d)", ptid, vt_my_trace);*/
      return vtcuptiCtx;
    }
    vtcuptiCtx = vtcuptiCtx->next;
  }
  CUPTI_UNLOCK();

  vt_cntl_msg(2, "[CUPTI] Context for VT tid %d unknown! Creating ... ", ptid);

  vtcuptiCtx = vt_cupti_initCtx(ptid, cuCtx);
  if(vtcuptiCtx != NULL){
    vt_cupti_start(vtcuptiCtx);
  }else{
    /* no performance counters for this thread available */
    vt_gpu_prop[ptid] |= VTGPU_NO_PC;
    vt_cntl_msg(2, "[CUPTI] Could not initialize!");
  }

  return vtcuptiCtx;
}
Beispiel #13
0
/*
 * Finalizes the VampirTrace CUPTI implementation.
 */
void vt_cupti_finalize()
{
  if(!vt_cupti_finalized){

    CUPTI_LOCK();
    if(!vt_cupti_finalized){

      vt_cntl_msg(2, "[CUPTI] Finalizing ...");

      /* free VampirTrace CUPTI context structures (should already be freed) */
      while(vtcuptiCtxlist != NULL){
        vt_cupti_ctx_t *tmp =  vtcuptiCtxlist;

        vt_cupti_finish(vtcuptiCtxlist);

        vtcuptiCtxlist = vtcuptiCtxlist->next;

        free(tmp);
        tmp = NULL;
      }

      /* free capability metric list */
      while(vt_cupti_capList != NULL){
        vt_cupti_dev_t *tmp = vt_cupti_capList;
        vt_cupti_capList = vt_cupti_capList->next;
        
        /* free VampirTrace CUPTI events */
        while(tmp->vtcuptiEvtList != NULL){
          vt_cupti_evt_t *tmpEvt = tmp->vtcuptiEvtList;
          tmp->vtcuptiEvtList = tmp->vtcuptiEvtList->next;
          free(tmpEvt);
          tmpEvt = NULL;
        }

        free(tmp);
        tmp = NULL;
      }

      vt_cupti_finalized = 1;
      CUPTI_UNLOCK();

#if (defined(VT_MT) || defined (VT_HYB))
      VTTHRD_LOCK_ENV();
      VTThrd_deleteMutex(&VTThrdMutexCupti);
      VTTHRD_UNLOCK_ENV();
#endif /* VT_MT || VT_HYB */
    }
  }
}
Beispiel #14
0
size_t vt_env_otf_bsize(void)
{
  static size_t bsize = 0;
  if (bsize == 0)
    {
      char* tmp = getenv("VT_OTF_BUFFER_SIZE");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_OTF_BUFFER_SIZE=%s", tmp);

          bsize = parse_size(tmp);
        }
    }
  return bsize;
}
Beispiel #15
0
size_t vt_env_compression_bsize(void)
{
  static size_t bsize = 0;
  if (bsize == 0)
    {
      char* tmp = getenv("VT_COMPRESSION_BUFFER_SIZE");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_COMPRESSION_BUFFER_SIZE=%s", tmp);

          bsize = parse_size(tmp);
        }
    }
  return bsize;
}
/*
 * Handles errors returned from CUPTI function calls.
 * 
 * @param ecode the CUDA driver API error code
 * @param msg a message to get more detailed information about the error
 * @param the corresponding file
 * @param the line the error occurred
 */
void vt_cupti_handleError(CUptiResult err, const char* msg,
                          const char *file, const int line)
{
  const char *errstr;
  
  if(msg != NULL) vt_cntl_msg(1, msg);
  
  cuptiGetResultString(err, &errstr);
  
  if(vt_gpu_error){
    vt_error_msg("[CUPTI] %s:%d:'%s'", file, line, errstr);
  }else{
    vt_warning("[CUPTI] %s:%d:'%s'", file, line, errstr);
  }
}
Beispiel #17
0
size_t vt_env_cudatrace_bsize()
{
  static size_t limit = 0;

  if (limit == 0)
    {
      char* tmp = getenv("VT_CUDATRACE_BUFFER_SIZE");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_CUDATRACE_BUFFER_SIZE=%s", tmp);

          limit = parse_size(tmp);
        }
    }
  return limit;
}
/*
 * Finalizes the VampirTrace CUPTI events interface.
 */
void vt_cupti_events_finalize()
{
  if(!vt_cuptievt_finalized && vt_cuptievt_initialized){ /* fast check without lock */
    VT_CUPTI_LOCK();
    if(!vt_cuptievt_finalized && vt_cuptievt_initialized){
      vt_cupti_ctx_t *vtcuptiCtxList =  vt_cupti_ctxList;
      
      /* needed because of the atexit in vt_cupti_events_init() */
      VT_SUSPEND_MALLOC_TRACING(VT_CURRENT_THREAD);

      vt_cntl_msg(2, "[CUPTI Events] Finalizing ...");

      /* free VampirTrace CUPTI events context structures */
      while(vtcuptiCtxList != NULL){
        if(vtcuptiCtxList->events != NULL){
          vt_cupti_events_finalizeContext(vtcuptiCtxList);
          free(vtcuptiCtxList->events);
          vtcuptiCtxList->events = NULL;
        }

        vtcuptiCtxList = vtcuptiCtxList->next;
      }

      /* free capability metric list */
      while(vtcuptievtCapList != NULL){
        vt_cupti_device_t *tmp = vtcuptievtCapList;
        vtcuptievtCapList = vtcuptievtCapList->next;
        
        /* free VampirTrace CUPTI events */
        while(tmp->vtcuptiEvtList != NULL){
          vt_cupti_evtctr_t *tmpEvt = tmp->vtcuptiEvtList;
          tmp->vtcuptiEvtList = tmp->vtcuptiEvtList->next;
          free(tmpEvt);
          tmpEvt = NULL;
        }

        free(tmp);
        tmp = NULL;
      }
      
      VT_RESUME_MALLOC_TRACING(VT_CURRENT_THREAD);

      vt_cuptievt_finalized = 1;
      VT_CUPTI_UNLOCK();
    }
  }
}
Beispiel #19
0
int vt_env_stat_msg_dtls()
{
  static int dtlsflags = 0;
  char* tmp;

  if (dtlsflags == 0)
    {
      tmp = getenv("VT_STAT_MSG_DTLS");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          char tmpbuf[128];
          char* p;
          char* tk;
          int dc;

          vt_cntl_msg(2, "VT_STAT_MSG_DTLS=%s", tmp);

          p = tmpbuf;
          strncpy(tmpbuf, tmp, 127);
          tmpbuf[127] = '\0';
          while( *p ) { *p = tolower(*p); p++; }

          tk = strtok(tmpbuf, ":");
          dc = 0;
          dtlsflags = 0;
          do {
            if (dc <= 2 &&
               (strcmp( tk, "peer" ) == 0))
              dtlsflags |= VT_SUM_MSG_DTL_PEER;
            else if(dc <= 2 &&
                    (strcmp( tk, "comm" ) == 0))
              dtlsflags |= VT_SUM_MSG_DTL_COMM;
            else if(dc <= 2 &&
                    (strcmp( tk, "tag" ) == 0))
              dtlsflags |= VT_SUM_MSG_DTL_TAG;
            else
              vt_error_msg("VT_STAT_MSG_DTLS not properly set");
            dc++;
          } while((tk = strtok(0, ":")));
        }
      else
        {
          dtlsflags = VT_SUM_MSG_DTL_PEER;
        }
    }
  return dtlsflags;
}
/*
 * Destroy a VampirTrace CUPTI Activity context.
 * 
 * @param vtcuptiActCtx VampirTrace CUPTI Activity context
 */
static void vt_cuptiact_destroyContext(vt_cupti_activity_t *vtcuptiActCtx)
{
  if(vtcuptiActCtx == NULL) 
    return;
  
  /* write exit event for GPU idle time */
  if(vt_gpu_trace_idle == 1 && vtcuptiActCtx->gpuIdleOn == 1){
    uint64_t idle_end = vt_pform_wtime();
    /*vt_warning("IDLEexit: %llu (%d)", idle_end, vtCtx->strmList->vtThrdID);*/
    vt_exit(vtcuptiActCtx->strmList->vtThrdID, &idle_end);
    /*vtCtx->gpuIdleOn = 0;*/
  }
  
  /* cleanup stream list */
  while(vtcuptiActCtx->strmList != NULL){
    vt_cuptiact_strm_t *vtStrm = vtcuptiActCtx->strmList;
    
    vtcuptiActCtx->strmList = vtcuptiActCtx->strmList->next;
    
    free(vtStrm);
    vtStrm = NULL;
  }
  
  /* free CUDA malloc entries, if user application has memory leaks */
  while(vtcuptiActCtx->gpuMemList != NULL){
    vt_cupti_gpumem_t *vtMem =  vtcuptiActCtx->gpuMemList;
    
    if(vt_gpu_trace_memusage > 1)
      vt_cntl_msg(1, "[CUPTI Activity] Free of %d bytes GPU memory missing!", 
                     vtMem->size);
    
    vtcuptiActCtx->gpuMemList = vtMem->next;
    free(vtMem);
    vtMem = NULL;
  }
  
  /* free activity buffer */
  if(vtcuptiActCtx->buffer != NULL){
    free(vtcuptiActCtx->buffer);
    vtcuptiActCtx->buffer = NULL;
  }
  
  free(vtcuptiActCtx);
}
Beispiel #21
0
int vt_env_mode()
{
  static int modeflags = 0;
  char* tmp;

  if (modeflags == 0)
    {
      tmp = getenv("VT_MODE");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          char tmpbuf[128];
          char* p;
          char* tk;
          int dc;

          vt_cntl_msg(2, "VT_MODE=%s", tmp);

          p = tmpbuf;
          strncpy(tmpbuf, tmp, 127);
          tmpbuf[127] = '\0';
          while( *p ) { *p = tolower(*p); p++; }

          tk = strtok(tmpbuf, ":");
          dc = 0;
          modeflags = 0;
          do {
            if (dc <= 1 &&
               (strcmp( tk, "trace" ) == 0))
              modeflags |= VT_MODE_TRACE;
            else if(dc <= 1 &&
                    (strcmp( tk, "stat" ) == 0))
              modeflags |= VT_MODE_STAT;
            else
              vt_error_msg("VT_MODE not properly set");
            dc++;
          } while((tk = strtok(0, ":")));
        }
      else
        {
          modeflags = VT_MODE_TRACE;
        }
    }
  return modeflags;
}
Beispiel #22
0
char* vt_env_iofsl_servers()
{
  static int read = 1;
  static char* iofsl_servers = NULL;
  char* tmp;

  if (read)
    {
      read = 0;
      tmp = getenv("VT_IOFSL_SERVERS");
      if (tmp && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_IOFSL_SERVERS=%s", tmp);

          iofsl_servers = tmp;
        }
    }
  return iofsl_servers;
}
void vt_cupti_init()
{
  if(!vt_cupti_initialized){
#if (defined(VT_MT) || defined(VT_HYB))
    VTThrd_createMutex(&VTThrdMutexCupti);
#endif
    VT_CUPTI_LOCK();
    if(!vt_cupti_initialized){
      vt_cntl_msg(2, "[CUPTI] Initializing ... ");
      
      /* register the finalize function of VampirTrace CUPTI to be called before
       * the program exits */
      atexit(vt_cupti_finalize);
      
      vt_cupti_initialized = 1;
      VT_CUPTI_UNLOCK();
    }
  }
}
Beispiel #24
0
char* vt_env_metrics()
{
  static int read = 1;
  static char* metrics = NULL;
  char* tmp;

  if (read)
    {
      read = 0;
      tmp = getenv("VT_METRICS");
      if (tmp && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_METRICS=%s", tmp);

          metrics = tmp;
        }
    }
  return metrics;
}
Beispiel #25
0
char* vt_env_java_filter_spec()
{
  static int read = 1;
  static char* spec = NULL;
  char* tmp;

  if (read)
    {
      read = 0;
      tmp = getenv("VT_JAVA_FILTER_SPEC");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_JAVA_FILTER_SPEC=%s", tmp);

          spec = replace_vars(tmp);
        }
    }
  return spec;
}
Beispiel #26
0
char* vt_env_groups_spec()
{
  static int read = 1;
  static char* spec = NULL;
  char* tmp;

  if (read)
    {
      read = 0;
      tmp = getenv("VT_GROUPS_SPEC");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_GROUPS_SPEC=%s", tmp);

          spec = replace_vars(tmp);
        }
    }
  return spec;
}
Beispiel #27
0
char* vt_env_dyn_shlibs()
{
  static int read = 1;
  static char* dyn_shlibs = NULL;
  char* tmp;

  if (read)
    {
      read = 0;
      tmp = getenv("VT_DYN_SHLIBS");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_DYN_SHLIBS=%s", tmp);

          dyn_shlibs = replace_vars(tmp);
        }
    }
  return dyn_shlibs;
}
Beispiel #28
0
char* vt_env_cupti_events()
{
  static int read = 1;
  static char* events = NULL;
  char* tmp;

  if (read)
    {
      read = 0;
      tmp = getenv("VT_CUPTI_METRICS");
      if (tmp && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_CUPTI_METRICS=%s", tmp);

          events = tmp;
        }
    }
  return events;
}
Beispiel #29
0
char* vt_env_gputrace()
{
  static int read = 1;
  static char* args = NULL;
  char* tmp;

  if (read)
    {
      read = 0;
      tmp = getenv("VT_GPUTRACE");
      if (tmp && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_GPUTRACE=%s", tmp);

          args = tmp;
        }
    }
  return args;
}
Beispiel #30
0
char* vt_env_gnu_nmfile()
{
  static int read = 1;
  static char* gnu_nmfile = NULL;
  char* tmp;

  if (read)
    {
      read = 0;
      tmp = getenv("VT_GNU_NMFILE");
      if (tmp != NULL && strlen(tmp) > 0)
        {
          vt_cntl_msg(2, "VT_GNU_NMFILE=%s", tmp);

          gnu_nmfile = replace_vars(tmp);
        }
    }
  return gnu_nmfile;
}