CUPTI User's Guide
CUPTI User's Guide
CUPTI User's Guide
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
simplify the presentation error checking code has been removed.static void <strong>CUPTI</strong>APIgetEventValueCallback ( void * userdata ,CUpti_CallbackDomain domain ,CUpti_CallbackId cbid ,const void * cbdata ){const CUpti_CallbackData * cbData =( CUpti_CallbackData *) cbdata ;if ( cbData -> callbackSite == <strong>CUPTI</strong>_API_ENTER ) {cudaThreadSynchronize ();cuptiSetEventCollectionMode ( cbInfo -> context ,<strong>CUPTI</strong>_EVENT_COLLECTION_MODE_KERNEL←↪);cuptiEventGroupEnable ( eventGroup );}if ( cbData -> callbackSite == <strong>CUPTI</strong>_API_EXIT ) {cudaThreadSynchronize ();cuptiEventGroupReadEvent ( eventGroup ,<strong>CUPTI</strong>_EVENT_READ_FLAG_ACCUMULATE ,eventId ,& bytesRead , & eventVal );}}cuptiEventGroupDisable ( eventGroup );Two synchronization points are used to ensure that events are counted only for theexecution of the kernel. If the application contains other threads that launch kernels, thenadditional thread-level synchronization must also be introduced to ensure that thosethreads do not launch kernels while the callback is collecting events. When thecudaLaunch API is entered (that is, before the kernel is actually launched on the device),cudaThreadSynchronize is used to wait until the GPU is idle. The event collection modeis set to <strong>CUPTI</strong>_EVENT_COLLECTION_MODE_KERNEL so that the event counters areautomatically started and stopped just before and after the kernel executes. Then eventcollection is enabled with cuptiEventGroupEnable.When the cudaLaunch API is exited (that is, after the kernel is queued for execution onthe GPU) another cudaThreadSynchronize is used to cause the CPU thread to wait forthe kernel to finish execution. Finally, the event counts are read withcuptiEventGroupReadEvent.CUDA Tools SDK <strong>CUPTI</strong> User’s <strong>Guide</strong> DA-05679-001_v01 | 10