How to profile only a part of my code(some kernels in a code piece)?

For example, I have a main function like this:

int main(){
//Disable nsight compute here

//Do some preparation using GPU.
//I don't want nsight compute collect metrics or anything else for this part.
prepare_data<<<XX, XXX>>>();

//Enable nsight compute to profile the following kernels

//My work begins


I just want to profile part of my code. Any idea?

You can use cu(da)ProfilerStart/Stop API. Nsight Compute by default profiles from the start of the application, but you can change this behavior with the –profile-from-start parameter. You can also filter kernels by name, count, skip or instrument the app with NVTX and limit profiling to selected NVTX ranges.

Thank you