-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Adds ROCmProfilerService and fixes NVProfilerService. #49580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ericcano
wants to merge
9
commits into
cms-sw:master
Choose a base branch
from
ericcano:NV-ROCm-ProfilerService
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
22c0e76
Adds ROCmProfilerService and fixes NVProfilerService.
162c7bf
Moves shared ProfilerService headers to PerTools.
3038fa0
Inclusions cleanup and creation of BuildFile.xml
0bcca00
Reinstates formerly present use and makes ProfilerService header only.
418456f
Fixes extra entry in BuildFiles.xml
6bdc6a1
Clarifies SpinLock construction and removes unused variables in ROCm …
07b90de
Removes leftover using statement
d7b622e
Update for removed signals & cleanup code.
deed0e1
Switches to TBB spinlocks + cleanup
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,426 changes: 209 additions & 1,217 deletions
1,426
HeterogeneousCore/CUDAServices/plugins/NVProfilerService.cc
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
HeterogeneousCore/ROCmServices/plugins/ROCmProfilerService.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #include <rocprofiler-sdk-roctx/roctx.h> | ||
|
|
||
| #include "HeterogeneousCore/ROCmServices/interface/ROCmInterface.h" | ||
|
|
||
| #include "PerfTools/ProfilerService/interface/ProfilerService.h" | ||
|
|
||
| namespace { | ||
| /** | ||
| * \brief Backend for ROCm profiling. | ||
| * \note All APIs used are part of ROCTX. See documentation at | ||
| * https://rocm.docs.amd.com/projects/rocprofiler-sdk/en/latest/how-to/using-rocprofiler-sdk-roctx.html | ||
| */ | ||
| class ROCmBackend { | ||
| public: | ||
| // Forward definitions | ||
| using Color = ProfilerServiceBase::Color; | ||
| using SpinLock = ProfilerServiceBase::SpinLock; | ||
| class Range; | ||
| class Domain; | ||
| static void mark(const Domain& domain, const char* message, Color color); | ||
| /** | ||
| * \note Latest doc is broken at time of writing, but older version is useful: | ||
| * https://rocm.docs.amd.com/projects/rocprofiler-sdk/en/docs-7.0.2/api-reference/rocprofiler-sdk-roctx_api/roctx_modules/profiler-control.html | ||
| */ | ||
| static void profilerStart() { | ||
| // 0 for all threads. | ||
| roctxProfilerResume(0); | ||
| } | ||
| static void profilerStop() { | ||
| // 0 for all threads. | ||
| roctxProfilerPause(0); | ||
| } | ||
|
|
||
| public: | ||
| using EDMService = edm::Service<ROCmInterface>; | ||
| class Domain { | ||
| public: | ||
| friend class Range; | ||
| friend void ROCmBackend::mark(const Domain& domain, const char* message, Color color); | ||
| Domain() = default; | ||
| ~Domain() = default; | ||
| void create(const std::string& name) { | ||
| // Assert the domain is created only once | ||
| assert(domain_.empty()); | ||
| domain_ = name; | ||
| } | ||
| void destroy() { domain_.clear(); } | ||
|
|
||
| private: | ||
| const std::string& nativeHandle() const { return domain_; } | ||
| std::string domain_; | ||
| }; | ||
|
|
||
| class Range { | ||
| public: | ||
| friend void ROCmBackend::mark(const Domain& domain, const char* message, Color color); | ||
| Range() = default; | ||
| // copy constructor deleted | ||
| Range(const Range&) = delete; | ||
| /// Move copy constructor: we take a lock and move the contents | ||
| /// We need it to resize vectors of unique_range_in | ||
| Range(Range&& o) noexcept { | ||
| std::scoped_lock lock(o.mtx_); | ||
| std::scoped_lock lock2(mtx_); | ||
| domain_ = o.domain_; | ||
| range_ = o.range_; | ||
| o.domain_.clear(); | ||
| o.range_ = roctxInvalidRangeId; | ||
| } | ||
| ~Range() { | ||
| std::scoped_lock lock(mtx_); | ||
| if (range_ != roctxInvalidRangeId) | ||
| roctxRangeStop(range_); | ||
| } | ||
|
|
||
| private: | ||
| roctx_range_id_t roctxDomainRangeStartColor(const Domain& domain, const char* message, uint32_t color) { | ||
| return roctxRangeStartA((domain.nativeHandle() + "-" + message).c_str()); | ||
| } | ||
|
|
||
| static constexpr roctx_range_id_t roctxInvalidRangeId = ~0ul; | ||
|
|
||
| public: | ||
| void startColorIn(const Domain& domain, const char* message, Color color, const char* where) { | ||
| std::scoped_lock lock(mtx_); | ||
| if (range_ != roctxInvalidRangeId) { | ||
| std::string fullmsg = | ||
| fmt::sprintf("Warning: previous range not ended before starting a new one in %s for %s", where, message); | ||
| roctxMarkA((domain_ + "-" + fullmsg).c_str()); | ||
| roctxRangeStop(range_); | ||
| } | ||
| domain_ = domain.nativeHandle(); | ||
| range_ = roctxRangeStartA((domain_ + "-" + message).c_str()); | ||
| } | ||
|
|
||
| void endIn(const Domain& domain, const char* message, const char* where) { | ||
| std::scoped_lock lock(mtx_); | ||
| if (range_ != roctxInvalidRangeId) { | ||
| roctxRangeStop(range_); | ||
| range_ = roctxInvalidRangeId; | ||
| domain_.clear(); | ||
| } else { | ||
| std::string fullmsg = | ||
| fmt::sprintf("Warning: trying to end a range that is not started in %s for %s", where, message); | ||
| roctxMarkA((domain_ + "-" + fullmsg).c_str()); | ||
| } | ||
| } | ||
|
|
||
| private: | ||
| roctx_range_id_t range_ = roctxInvalidRangeId; | ||
| std::string domain_; | ||
| SpinLock mtx_ = SpinLock{}; | ||
| }; | ||
|
|
||
| static std::string shortName() { return "ROCm"; } | ||
| static std::string serviceComment() { | ||
| return R"(This Service provides CMSSW-aware annotations to nvprof/nvvm. | ||
|
|
||
| Notes on nvprof options: | ||
| - the option '--profile-from-start off' should be used if skipFirstEvent is True. | ||
| - the option '--cpu-profiling on' currently results in cmsRun being stuck at the beginning of the job. | ||
| - the option '--cpu-thread-tracing on' is not compatible with jemalloc, and should only be used with cmsRunGlibC.)"; | ||
| } | ||
| }; | ||
|
|
||
| void ROCmBackend::mark(const ROCmBackend::Domain& domain, const char* message, Color color) { | ||
| roctxMark(("[" + domain.nativeHandle() + "]: " + std::string(message)).c_str()); | ||
| } | ||
| } // namespace | ||
|
|
||
| class ROCmProfilerService : public ProfilerService<ROCmBackend> { | ||
| public: | ||
| using ProfilerService<ROCmBackend>::ProfilerService; | ||
| }; | ||
|
|
||
| #include "FWCore/ServiceRegistry/interface/ServiceMaker.h" | ||
| DEFINE_FWK_SERVICE(ROCmProfilerService); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <export> | ||
| <use name="boost"/> | ||
| <use name="fmt" /> | ||
| <use name="tbb"/> | ||
| <use name="DataFormats/Provenance"/> | ||
| <use name="FWCore/Framework"/> | ||
| <use name="FWCore/ParameterSet"/> | ||
| <use name="FWCore/ServiceRegistry"/> | ||
| </export> | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.