/* * De-initialize the VampirTrace CUPTI context without destroying it. * * @param vtcuptiCtx pointer to the VampirTrace CUPTI context */ static void vt_cupti_finish(vt_cupti_ctx_t *vtcuptiCtx) { CUptiResult cuptiErr = CUPTI_SUCCESS; if(vtcuptiCtx == NULL || vt_gpu_debug) return; /*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; } } }
/* * 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); }
/* * 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); }
void vt_cupti_events_finalizeContext(vt_cupti_ctx_t *vtCtx) { uint64_t time = vt_pform_wtime(); vt_cupti_strm_t *curStrm = NULL; vt_cupti_evtgrp_t *vtcuptiGrp = NULL; if(vtCtx == NULL || vtCtx->events == NULL) return; /* These CUPTI calls may fail, as CUPTI has implicitly destroyed something */ if(vt_gpu_debug == 0){ curStrm = vtCtx->strmList; /* for all streams of this context */ while(curStrm != NULL){ /* ensure increasing time stamps */ if(time < curStrm->vtLastTime){ curStrm = curStrm->next; continue; } vt_cuptievt_resetCounter(vtCtx->events, curStrm->vtThrdID, &time); curStrm = curStrm->next; } /* stop CUPTI counter capturing */ vt_cuptievt_stop(vtCtx->events); /* destroy all CUPTI event groups, which have been created */ vtcuptiGrp = vtCtx->events->vtGrpList; while(vtcuptiGrp != NULL){ VT_CUPTI_CALL(cuptiEventGroupRemoveAllEvents(vtcuptiGrp->evtGrp), "cuptiEventGroupRemoveAllEvents"); VT_CUPTI_CALL(cuptiEventGroupDestroy(vtcuptiGrp->evtGrp), "cuptiEventGroupDestroy"); vtcuptiGrp = vtcuptiGrp->next; } }else{ /* set at least the VampirTrace counter to zero */ curStrm = vtCtx->strmList; /* for all streams of this context */ while(curStrm != NULL){ /* ensure increasing time stamps */ if(time < curStrm->vtLastTime){ curStrm = curStrm->next; continue; } vtcuptiGrp = vtCtx->events->vtGrpList; while(vtcuptiGrp != NULL){ size_t i; for(i = 0; i < vtcuptiGrp->evtNum; i++){ vt_count(curStrm->vtThrdID, &time, *(vtcuptiGrp->vtCIDs+i), 0); } vtcuptiGrp = vtcuptiGrp->next; } curStrm = curStrm->next; } } /* free previously allocated memory */ vt_cuptievt_freeEventCtx(vtCtx->events); }