11.07.2015 Views

CUPTI User's Guide

CUPTI User's Guide

CUPTI User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

esource tracking, and a domain for CUDA synchronization notification.Callback ID: Each callback is given a unique ID within the corresponding callback domainso that you can identify it within your callback function. The CUDA driver API IDsare defined in cupti_driver_cbid.h and the CUDA runtime API IDs are defined incupti_runtime_cbid.h. Both of these headers are included for you when youinclude cupti.h. The CUDA resource callback IDs are defined byCUpti_CallbackIdResource and the CUDA synchronization callback IDs are definedby CUpti_CallbackIdSync.Callback Function: Your callback function must be of type CUpti_CallbackFunc. Thisfunction type has two arguments that specify the callback domain and ID so thatyou know why the callback is occurring. The type also has a cbdata argument thatis used to pass data specific to the callback.Subscriber: A subscriber is used to associate each of your callback functions with one ormore CUDA API functions. There can be at most one subscriber initialized withcuptiSubscribe() at any time. Before initializing a new subscriber, the existingsubscriber must be finalized with cuptiUnsubscribe().Each callback domain is described in detail below.Driver and Runtime API CallbacksUsing the callback API with the <strong>CUPTI</strong>_CB_DOMAIN_DRIVER_API or<strong>CUPTI</strong>_CB_DOMAIN_RUNTIME_API domains, you can associate a callback function with oneor more CUDA API functions. When those CUDA functions are invoked in theapplication, your callback function is invoked as well. For these domains, the cbdataargument to your callback function will be of the type CUpti_CallbackData.The following code shows a typical sequence used to associate a callback function with oneor more CUDA API functions. To simplify the presentation error checking code has beenremoved.CUpti_SubscriberHandle subscriber ;MyDataStruct * my_data = ...;...cuptiSubscribe (& subscriber ,( CUpti_CallbackFunc ) my_callback , my_data );cuptiEnableDomain (1, subscriber ,<strong>CUPTI</strong>_CB_DOMAIN_RUNTIME_API );First, cuptiSubscribe is used to initialize a subscriber with the my_callback callbackfunction. Next, cuptiEnableDomain is used to associate that callback with all the CUDAruntime API functions. Using this code sequence will cause my_callback to be calledCUDA Tools SDK <strong>CUPTI</strong> User’s <strong>Guide</strong> DA-05679-001_v01 | 6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!