static void handleResource(CUpti_CallbackId cbid, const CUpti_ResourceData *resourceData) { // enqueue buffers on a context's queue when the context is created if (cbid == CUPTI_CBID_RESOURCE_CONTEXT_CREATED) { queueNewBuffer(resourceData->context, 0); queueNewBuffer(resourceData->context, 0); } // dump all buffers on a context destroy else if (cbid == CUPTI_CBID_RESOURCE_CONTEXT_DESTROY_STARTING) { while (dump(resourceData->context, 0) != NULL) ; } // enqueue buffers on a stream's queue when a non-default stream is created if (cbid == CUPTI_CBID_RESOURCE_STREAM_CREATED) { uint32_t streamId; CUPTI_CALL(cuptiGetStreamId(resourceData->context, resourceData->resourceHandle.stream, &streamId)); queueNewBuffer(resourceData->context, streamId); queueNewBuffer(resourceData->context, streamId); } // dump all buffers on a stream destroy else if (cbid == CUPTI_CBID_RESOURCE_STREAM_DESTROY_STARTING) { uint32_t streamId; CUPTI_CALL(cuptiGetStreamId(resourceData->context, resourceData->resourceHandle.stream, &streamId)); while (dump(resourceData->context, streamId) != NULL) ; } }
void initTrace() { // Enqueue a couple of buffers in the global queue queueNewBuffer(NULL, 0); queueNewBuffer(NULL, 0); // device activity record is created when CUDA initializes, so we // want to enable it before cuInit() or any CUDA runtime call CUPTI_CALL(cuptiActivityEnable(CUPTI_ACTIVITY_KIND_DEVICE)); // CUPTI_CALL(cuptiActivityEnable(CUPTI_ACTIVITY_KIND_MEMCPY)); cuptiActivityEnable(CUPTI_ACTIVITY_KIND_CONTEXT); // cuptiActivityEnable(CUPTI_ACTIVITY_KIND_DRIVER); // cuptiActivityEnable(CUPTI_ACTIVITY_KIND_RUNTIME); cuptiActivityEnable(CUPTI_ACTIVITY_KIND_MEMCPY); cuptiActivityEnable(CUPTI_ACTIVITY_KIND_MEMSET); cuptiActivityEnable(CUPTI_ACTIVITY_KIND_KERNEL); CUpti_SubscriberHandle subscriber; CUPTI_CALL(cuptiSubscribe(&subscriber, (CUpti_CallbackFunc)traceCallback, NULL)); CUPTI_CALL(cuptiEnableDomain(1, subscriber, CUPTI_CB_DOMAIN_RESOURCE)); CUPTI_CALL(cuptiEnableDomain(1, subscriber, CUPTI_CB_DOMAIN_SYNCHRONIZE)); //add by wukai //CUPIT_CALL(cuptiEnableDomain(1, subscriber, CUPTI_CB_DOMAIN_RUNTIME_API)); CUPTI_CALL(cuptiGetTimestamp(&startTimestamp)); }