Skip to content

Commit

Permalink
Fixed CUPTI on Windows (#830)
Browse files Browse the repository at this point in the history
Summary:
Fixed 2 compiling errors on Windows.
Changed callbackLock_ from static to member of the class since on Windows Release in Pytorch CuptiCallbackApi::initCallbackApi gets called before the static initialisation of the mutex so it crashes.

Pull Request resolved: #830

Reviewed By: aaronenyeshi

Differential Revision: D51314940

Pulled By: davidberard98

fbshipit-source-id: 4de09332320bb15063859be2e43a9eb1e308c6fb
  • Loading branch information
mantaionut authored and facebook-github-bot committed Nov 15, 2023
1 parent b885c64 commit 33fdaad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
8 changes: 0 additions & 8 deletions libkineto/src/CuptiCallbackApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <chrono>
#include <algorithm>
#include <mutex>
#include <shared_mutex>

#ifdef HAS_CUPTI
#include "cupti_call.h"
Expand All @@ -32,13 +31,6 @@ constexpr size_t MAX_CB_FNS_PER_CB = 8;
// is enabled, not a specific cbid.
constexpr uint32_t MAX_CUPTI_CALLBACK_ID_ALL = 0xffffffff;

// Reader Writer lock types
using ReaderWriterLock = std::shared_timed_mutex;
using ReaderLockGuard = std::shared_lock<ReaderWriterLock>;
using WriteLockGuard = std::unique_lock<ReaderWriterLock>;

static ReaderWriterLock callbackLock_;

/* Callback Table :
* Overall goal of the design is to optimize the lookup of function
* pointers. The table is structured at two levels and the leaf
Expand Down
7 changes: 7 additions & 0 deletions libkineto/src/CuptiCallbackApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <list>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <set>

// TODO(T90238193)
Expand Down Expand Up @@ -143,6 +144,12 @@ class CuptiCallbackApi {
// As an implementation detail, cbid == 0xffffffff means enable the domain.
std::set<std::pair<CUpti_CallbackDomain, CUpti_CallbackId>> enabledCallbacks_;


// Reader Writer lock types
using ReaderWriterLock = std::shared_timed_mutex;
using ReaderLockGuard = std::shared_lock<ReaderWriterLock>;
using WriteLockGuard = std::unique_lock<ReaderWriterLock>;
ReaderWriterLock callbackLock_;
#ifdef HAS_CUPTI
CUptiResult lastCuptiStatus_;
CUpti_SubscriberHandle subscriber_ {0};
Expand Down
16 changes: 8 additions & 8 deletions libkineto/src/CuptiRangeProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ CuptiRangeProfilerSession::CuptiRangeProfilerSession(
LOG(INFO) << "\t" << m;
}

CuptiRangeProfilerOptions opts{
.metricNames = cupti_metrics,
.deviceId = 0,
.maxRanges = max_ranges,
.numNestingLevels = 1,
.cuContext = nullptr,
.unitTest = false};

CuptiRangeProfilerOptions opts;
opts.metricNames = cupti_metrics;
opts.deviceId = 0;
opts.maxRanges = max_ranges;
opts.numNestingLevels = 1;
opts.cuContext = nullptr;
opts.unitTest = false;
for (auto device_id : CuptiRBProfilerSession::getActiveDevices()) {
LOG(INFO) << "Init CUPTI range profiler on gpu = " << device_id
<< " max ranges = " << max_ranges;
Expand Down
1 change: 0 additions & 1 deletion libkineto/src/CuptiRangeProfilerConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <Logger.h>

#include <stdlib.h>
#include <unistd.h>

#include <fmt/format.h>
#include <ostream>
Expand Down

0 comments on commit 33fdaad

Please sign in to comment.