Cuda Performance Metrics/Profiling#198
Conversation
67097ab to
f7d6902
Compare
| CUpti_MetricValue value; | ||
| }; | ||
|
|
||
| using KernelTy = std::function<void(void)>; |
| size_t eventNameSize = sizeof(eventName) - 1; | ||
| TC_CUPTI_CHECK(cuptiEventGetAttribute( | ||
| eventId, CUPTI_EVENT_ATTR_NAME, &eventNameSize, eventName)); | ||
| eventName[127] = '\0'; |
There was a problem hiding this comment.
eventName[eventNameSize] ?
| TC_CUPTI_CHECK(cuptiEventGetAttribute( | ||
| eventId, CUPTI_EVENT_ATTR_NAME, &eventNameSize, eventName)); | ||
| eventName[127] = '\0'; | ||
| CHECK_GT(eventNameSize, 0); |
There was a problem hiding this comment.
Move before and also check < 128?
| uint64_t sum, | ||
| uint64_t normalized, | ||
| uint64_t* values) { | ||
| char eventName[128]; |
There was a problem hiding this comment.
constexpr blah = 128; ?
| } | ||
| } | ||
| ss << ')'; | ||
| LOG(INFO) << ss.str(); |
There was a problem hiding this comment.
cleanup plz, maybe it already is cleaned up?
|
|
||
| ss << eventName << " (normalized) (" << sum << " * " << numTotalInstances | ||
| << ") / " << numInstances << " = " << normalized; | ||
| LOG(INFO) << ss.str(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
ScopeGuard([]{free(eventIds);});
| eventIds[j], | ||
| &valuesSize, | ||
| values.data())); | ||
| CHECK_EQ(numInstances, valuesSize / sizeof(uint64_t)); |
There was a problem hiding this comment.
If these CHECKs are expected to get hit regularly, consider throwing instead
| } | ||
| } | ||
|
|
||
| uint64_t metricValueAsUint64(const CudaMetric& metric) { |
There was a problem hiding this comment.
Can you make this function and the next 2 be member methods called as<T> and only instantiated for the proper types?
| kernel_(); | ||
| } | ||
|
|
||
| // XXX:this check fails with some combinations of metrics my assumption is |
There was a problem hiding this comment.
dead code removal, plz
| std::vector<const void*> inputs) const { | ||
| int dev; | ||
| TC_CUDA_RUNTIMEAPI_ENFORCE(cudaGetDevice(&dev)); | ||
| if (perGpuModule_.count(dev) == 0) { |
There was a problem hiding this comment.
Factor out and reuse across functions plz
e1c97c1 to
fc1f2d1
Compare
| // 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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
This is likely going to be non-core team facing API, please document the function
| ${CUDA_curand_LIBRARY} | ||
| ${CUDA_LIBRARIES} | ||
| ${CUDA_NVRTC_LIBRARIES} | ||
| ${CUDA_cupti_LIBRARY} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
find_package(cuda) should have set it. Is there a cupti directory under cuda_root_dir/extras in your machine?
skimo-openhub
left a comment
There was a problem hiding this comment.
Make sure 4715b90 gets squashed into the appropriate commit before merging.
1b57f34 to
74cdd3e
Compare
|
On Tue, Apr 03, 2018 at 08:29:43AM -0700, Theodoros Theodoridis wrote:
ttheodor commented on this pull request.
> target_link_libraries(
tc_cuda
${CUDA_CUDA_LIBRARIES}
${CUDA_curand_LIBRARY}
${CUDA_LIBRARIES}
${CUDA_NVRTC_LIBRARIES}
+ ${CUDA_cupti_LIBRARY}
`find_package(cuda)` should have set it. Is there a cupti directory under `cuda_root_dir/extras` in your machine?
No, I don't have that on any of my machines.
Do I need to install something extra?
Then please update the documentation in this commit.
skimo
|
|
You shouldn't have to install it separately (I didn't). |
|
@caffe2bot retest this please |
| } else { | ||
| CHECK(false) << "Invalid metric value conversion."; | ||
| } | ||
| } |
There was a problem hiding this comment.
These functions result in warnings about control reaching
end of non-void function.
There was a problem hiding this comment.
The compiler can't figure out that CHECK(false) always leads to program termination. I could return dummy values to make the compiler happy.
There was a problem hiding this comment.
Or use something like __builtin_unreachable
|
On Tue, Apr 03, 2018 at 05:39:57PM +0200, Sven Verdoolaege wrote:
On Tue, Apr 03, 2018 at 08:29:43AM -0700, Theodoros Theodoridis wrote:
> ttheodor commented on this pull request.
> > target_link_libraries(
> tc_cuda
>
> ${CUDA_CUDA_LIBRARIES}
> ${CUDA_curand_LIBRARY}
> ${CUDA_LIBRARIES}
> ${CUDA_NVRTC_LIBRARIES}
> + ${CUDA_cupti_LIBRARY}
>
> `find_package(cuda)` should have set it. Is there a cupti directory under `cuda_root_dir/extras` in your machine?
No, I don't have that on any of my machines.
Do I need to install something extra?
Installing the package `libcupti-dev` solved the problem for me.
skimo
|
|
On Wed, Apr 04, 2018 at 09:58:34AM +0000, Theodoros Theodoridis wrote:
ttheodor commented on this pull request.
> + size_t valueKindSize = sizeof(valueKind);
+ TC_CUPTI_CHECK(cuptiMetricGetAttribute(
+ metric.id, CUPTI_METRIC_ATTR_VALUE_KIND, &valueKindSize, &valueKind));
+ return valueKind;
+}
+
+double metricValueAsDouble(const CudaMetric& metric) {
+ auto valueKind = getValueKind(metric);
+ if (valueKind == CUPTI_METRIC_VALUE_KIND_DOUBLE) {
+ return metric.value.metricValueDouble;
+ } else if (valueKind == CUPTI_METRIC_VALUE_KIND_PERCENT) {
+ return metric.value.metricValuePercent;
+ } else {
+ CHECK(false) << "Invalid metric value conversion.";
+ }
+}
The compiler can't figure out that `CHECK(false)` always leads to program termination. I could return dummy values to make the compiler happy.
Please do.
skimo
|
| // 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
The commit message refers to CUDA version. The check is on CUPTI version (their versions are tied but they use different numbers).
There was a problem hiding this comment.
I'll squash it in the right commit.
|
On Wed, Apr 04, 2018 at 02:46:15PM +0000, Theodoros Theodoridis wrote:
ttheodor commented on this pull request.
> @@ -116,7 +116,11 @@ void CUPTIAPI bufferCompleted(
// 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)
The commit message refers to CUDA version. The check is on CUPTI version (their versions are tied but they use different numbers).
Thanks. I missed that.
skimo
|
c18f652 to
d596872
Compare
c98f779 to
63bc46f
Compare
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).
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).