Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Cuda Performance Metrics/Profiling#198

Open
thetheodor wants to merge 7 commits into
masterfrom
cupti
Open

Cuda Performance Metrics/Profiling#198
thetheodor wants to merge 7 commits into
masterfrom
cupti

Conversation

@thetheodor

@thetheodor thetheodor commented Mar 23, 2018

Copy link
Copy Markdown

Add CUPTI-based profiling functionality in CudaRTCFun.

There are several performance metrics (listed here. Each metric requires measuring (possibly multiple types of) hardware events. Since not all events can be measured at the same time, a kernel must be launched multiple times (it's 12 times with the current list of hardcoded metrics).

@prigoyal prigoyal added the wip label Mar 23, 2018
@thetheodor thetheodor changed the title [RFC] Cuda Profiling Cuda Performance Metrics/Profiling Mar 24, 2018
@thetheodor thetheodor removed the wip label Mar 24, 2018
@thetheodor thetheodor force-pushed the cupti branch 2 times, most recently from 67097ab to f7d6902 Compare March 28, 2018 17:16
Comment thread include/tc/core/cuda/cuda_profile.h Outdated
CUpti_MetricValue value;
};

using KernelTy = std::function<void(void)>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KernelType ?

Comment thread src/core/cuda/cuda_profile.cc Outdated
size_t eventNameSize = sizeof(eventName) - 1;
TC_CUPTI_CHECK(cuptiEventGetAttribute(
eventId, CUPTI_EVENT_ATTR_NAME, &eventNameSize, eventName));
eventName[127] = '\0';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventName[eventNameSize] ?

Comment thread src/core/cuda/cuda_profile.cc Outdated
TC_CUPTI_CHECK(cuptiEventGetAttribute(
eventId, CUPTI_EVENT_ATTR_NAME, &eventNameSize, eventName));
eventName[127] = '\0';
CHECK_GT(eventNameSize, 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move before and also check < 128?

Comment thread src/core/cuda/cuda_profile.cc Outdated
uint64_t sum,
uint64_t normalized,
uint64_t* values) {
char eventName[128];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constexpr blah = 128; ?

}
}
ss << ')';
LOG(INFO) << ss.str();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup plz, maybe it already is cleaned up?

Comment thread src/core/cuda/cuda_profile.cc Outdated

ss << eventName << " (normalized) (" << sum << " * " << numTotalInstances
<< ") / " << numInstances << " = " << normalized;
LOG(INFO) << ss.str();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup plz, maybe it already is cleaned up?

TC_CUPTI_CHECK(cuptiEventGroupGetAttribute(
group, CUPTI_EVENT_GROUP_ATTR_NUM_EVENTS, &numEventsSize, &numEvents));
eventIdsSize = numEvents * sizeof(CUpti_EventID);
eventIds = (CUpti_EventID*)malloc(eventIdsSize);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScopeGuard([]{free(eventIds);});

eventIds[j],
&valuesSize,
values.data()));
CHECK_EQ(numInstances, valuesSize / sizeof(uint64_t));

@nicolasvasilache nicolasvasilache Apr 3, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these CHECKs are expected to get hit regularly, consider throwing instead

Comment thread src/core/cuda/cuda_profile.cc Outdated
}
}

uint64_t metricValueAsUint64(const CudaMetric& metric) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this function and the next 2 be member methods called as<T> and only instantiated for the proper types?

Comment thread src/core/cuda/cuda_profile.cc Outdated
kernel_();
}

// XXX:this check fails with some combinations of metrics my assumption is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code removal, plz

Comment thread src/core/cuda/cuda_rtc.cc Outdated
std::vector<const void*> inputs) const {
int dev;
TC_CUDA_RUNTIMEAPI_ENFORCE(cudaGetDevice(&dev));
if (perGpuModule_.count(dev) == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factor out and reuse across functions plz

@thetheodor thetheodor force-pushed the cupti branch 2 times, most recently from e1c97c1 to fc1f2d1 Compare April 3, 2018 14:33
// Steal the executor instance and give it back under lock.
// Run outside of lock on owning ExecutorType.
template <typename ExecutorType>
typename ExecutorType::ProfilingInfoType ExecutionEngine<ExecutorType>::profile(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please definitely not copy-paste this piece as it involves tricky concurrent code.
Let's instead factor out the code in another function and pass it a std::function since the only difference seems to be to call run vs profile.

/// data in GPU address space.
/// No tensor-related information can be checked so it is the user's
/// responsibility to ensure that shapes and strides match.
typename ExecutorType::ProfilingInfoType profile(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely going to be non-core team facing API, please document the function

Comment thread src/core/CMakeLists.txt
${CUDA_curand_LIBRARY}
${CUDA_LIBRARIES}
${CUDA_NVRTC_LIBRARIES}
${CUDA_cupti_LIBRARY}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CUDA_cupti_LIBRARY doesn't seem to be defined anywhere.

I get

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_cupti_LIBRARY (ADVANCED)
    linked by target "tc_cuda" in directory /home/skimo/git/c2isl/src/core

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_package(cuda) should have set it. Is there a cupti directory under cuda_root_dir/extras in your machine?

@skimo-openhub skimo-openhub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure 4715b90 gets squashed into the appropriate commit before merging.

@thetheodor thetheodor force-pushed the cupti branch 2 times, most recently from 1b57f34 to 74cdd3e Compare April 3, 2018 15:31
@skimo-openhub

skimo-openhub commented Apr 3, 2018 via email

Copy link
Copy Markdown
Contributor

@thetheodor

Copy link
Copy Markdown
Author

You shouldn't have to install it separately (I didn't).

The CUPTI library is supported on all platforms supported by the CUDA Toolkit, and is available on the CUDA Downloads page as part of the CUDA Tools SDK.

@nicolasvasilache

Copy link
Copy Markdown
Contributor

@caffe2bot retest this please

Comment thread src/core/cuda/cuda_profile.cc Outdated
} else {
CHECK(false) << "Invalid metric value conversion.";
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions result in warnings about control reaching
end of non-void function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler can't figure out that CHECK(false) always leads to program termination. I could return dummy values to make the compiler happy.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use something like __builtin_unreachable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do.

@skimo-openhub

skimo-openhub commented Apr 4, 2018 via email

Copy link
Copy Markdown
Contributor

@skimo-openhub

skimo-openhub commented Apr 4, 2018 via email

Copy link
Copy Markdown
Contributor

// since we launched only 1 kernel, we should have only 1 kernel record
TC_CUPTI_CHECK(cuptiActivityGetNextRecord(buffer, validSize, &record));

#if (CUPTI_API_VERSION >= 10)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't seem to match the commit message.
You're doing something special for versions "> 9.0" not "< 9.0".
I don't know which of the two is correct.
However, you seem to be modifying new code, so this should be squashed in.
There is no point in introducing known broken commits.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message refers to CUDA version. The check is on CUPTI version (their versions are tied but they use different numbers).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll squash it in the right commit.

@skimo-openhub

skimo-openhub commented Apr 4, 2018 via email

Copy link
Copy Markdown
Contributor

@thetheodor thetheodor force-pushed the cupti branch 7 times, most recently from c18f652 to d596872 Compare April 11, 2018 16:04
@thetheodor thetheodor force-pushed the cupti branch 7 times, most recently from c98f779 to 63bc46f Compare April 17, 2018 11:17
Theodoros Theodoridis added 7 commits April 25, 2018 13:13
CUPTI is used to query gpu performance counters/events and compute
metrics such as occupancy. Not all events can be measured in one run, as
such for a particular metric multiple kernel launches might be required.

This commit only includes a set of hardcoded metrics (later on these
should be selectable).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants