Skip to content
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

[ORC][JITLink] Add Intel VTune support to JITLink #81826

Merged
merged 3 commits into from
Mar 4, 2024

Conversation

yugier
Copy link
Contributor

@yugier yugier commented Feb 15, 2024

This patch adds two plugins: VTuneSupportPlugin.cpp and JITLoaderVTune.cpp. The testing is done in a manner similar to llvm-jitlistener. Currently, we only support the old version of Intel VTune API.

This pull request is stacked on top of #81825

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@yugier
Copy link
Contributor Author

yugier commented Feb 15, 2024

@lhames Could you please help me to review this one and #81825? Thank you!

Copy link

github-actions bot commented Feb 15, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff bc9c6c0c65e267a1a84e4eede81099d8ceb37558 4bc5719084d7ace375e524cca2dca942e1d90f20 -- llvm/include/llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.cpp llvm/tools/llvm-jitlink/llvm-jitlink.cpp
View the diff from clang-format here.
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h
index a9fa9967ac..8c63a9aa47 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h
@@ -1,5 +1,6 @@
 
-//===------- JITLoaderVTune.h --- Register profiler objects ------*- C++ -*-===//
+//===------- JITLoaderVTune.h --- Register profiler objects ------*- C++
+//-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -27,5 +28,3 @@ extern "C" llvm::orc::shared::CWrapperFunctionResult
 llvm_orc_test_registerVTuneImpl(const char *Data, uint64_t Size);
 
 #endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_JITLOADERVTUNE_H
-
-
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 0217f645a0..09b2a5900e 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -1015,9 +1015,10 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
 
   if (VTuneSupport && TT.isOSBinFormatELF()) {
     ObjLayer.addPlugin(ExitOnErr(DebugInfoPreservationPlugin::Create()));
-    ObjLayer.addPlugin(ExitOnErr(VTuneSupportPlugin::Create(
-        this->ES.getExecutorProcessControl(), *ProcessSymsJD, /*EmitDebugInfo=*/true,
-        /*TestMode=*/true)));
+    ObjLayer.addPlugin(ExitOnErr(
+        VTuneSupportPlugin::Create(this->ES.getExecutorProcessControl(),
+                                   *ProcessSymsJD, /*EmitDebugInfo=*/true,
+                                   /*TestMode=*/true)));
   }
 
   // Set up the platform.

@dtcxzyw dtcxzyw requested a review from lhames February 15, 2024 08:01
Comment on lines 45 to 47
if (I != Deduplicator.end()) {
return I->second;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The LLVM style guide omits braces for single line statements, so this could just be:

if (I != Deduplicator.end())
  return I->second;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed(all of them)!

Comment on lines 166 to 167
auto I = LoadedMethodIDs.find(SrcKey);
if (I == LoadedMethodIDs.end()) {
return;
}
auto &Dest = LoadedMethodIDs[DstKey];
Dest.insert(Dest.end(), I->second.begin(), I->second.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a LoadedMethodIDs.erase(SrcKey) at the end to remove the stale key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I just added it. Thank you for finding it out!

Copy link
Contributor

@lhames lhames left a comment

Choose a reason for hiding this comment

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

Thanks @yugier. This looking great -- thank you very much for working on this!

This patch adds two plugins: VTuneSupportPlugin.cpp and
JITLoaderVTune.cpp. The testing is done in a manner similar to
llvm-jitlistener. Currently, we only support the old version of Intel
VTune API.
@yugier
Copy link
Contributor Author

yugier commented Mar 4, 2024

Force push to rebase on #81825

@mshockwave mshockwave merged commit 17efdad into llvm:main Mar 4, 2024
2 of 4 checks passed
Copy link

github-actions bot commented Mar 4, 2024

@yugier Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@MaskRay
Copy link
Member

MaskRay commented Mar 4, 2024

Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

This change introduced a cyclic dependency, which appears difficult to resolve.
(https://llvm.org/docs/CodingStandards.html#library-layering)

The library dependencies look like: LLVMOrcDebugging -> LLVMOrcJIT -> LLVMOrcTargetProcess. LLVMOrcTargetProcess should not include headers belonging to LLVMOrcDebugging (#include "llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h" in llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.cpp).

This is best demonstrated as a Bazel build failure
(Bazel is an unofficial build system, so contributors are not obliged to make it work, but library layering issues should be fixed. The CMake build system does not track headers.)

% cd utils/bazel/llvm-project-overlay
% bazel-6.3.2 build --config=generic_clang @llvm-project//llvm:OrcTargetProcess
INFO: Analyzed target @llvm-project//llvm:OrcTargetProcess (1 packages loaded, 3373 targets configured).
INFO: Found 1 target...
ERROR: /.cache/bazel/_bazel_maskray/f4f2a5f8f860ef21363a22b3fde46672/external/llvm-project/llvm/BUILD.bazel:2862:11: Compiling llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.cpp failed: (Exit 1): clang failed: error executing command (from target @llvm-project//llvm:OrcTargetProcess) /usr/lib/llvm-16/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer ... (remaining 99 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
external/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.cpp:13:10: fatal error: 'llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h' file not found
#include "llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you add a dependency

--- i/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ w/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -2888,2 +2888,3 @@ cc_library(
         ":Object",
+        ":OrcDebugging",
         ":OrcShared",

Bazel will show a cycle

.-> @llvm-project//llvm:OrcTargetProcess (c81a3717a11045af15f5d7ff5d22d9e3312985441ac5f30b7a838ba8a61ec69e)
|   @llvm-project//llvm:OrcDebugging (c81a3717a11045af15f5d7ff5d22d9e3312985441ac5f30b7a838ba8a61ec69e)
|   @llvm-project//llvm:OrcJIT (c81a3717a11045af15f5d7ff5d22d9e3312985441ac5f30b7a838ba8a61ec69e)
`-- @llvm-project//llvm:OrcTargetProcess (c81a3717a11045af15f5d7ff5d22d9e3312985441ac5f30b7a838ba8a61ec69e)

MaskRay added a commit to MaskRay/llvm-project that referenced this pull request Mar 4, 2024
This reverts commit 17efdad.

The library dependencies look like: LLVMOrcDebugging -> LLVMOrcJIT -> LLVMOrcTargetProcess.
`#include "llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h"` in
llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.cpp introduced
a cyclic dependency.
rupprecht added a commit that referenced this pull request Mar 5, 2024
@rupprecht
Copy link
Collaborator

The revert above was on a fork, so 1a67dee applies the revert to the main repo.

@MaskRay
Copy link
Member

MaskRay commented Mar 5, 2024

The revert above was on a fork, so 1a67dee applies the revert to the main repo.

The revert above was created as #83909 , which I am abandoning now that you revert was pushed...

@rupprecht
Copy link
Collaborator

The revert above was on a fork, so 1a67dee applies the revert to the main repo.

The revert above was created as #83909 , which I am abandoning now that you revert was pushed...

Ah, my bad -- I figured it was just an accident the revert was on a fork, didn't realize it was intentionally done so it could be done as a PR.

yugier added a commit to yugier/llvm-project that referenced this pull request Mar 5, 2024
This patch relands llvm#81826

This patch adds two plugins: VTuneSupportPlugin.cpp and
JITLoaderVTune.cpp. The testing is done in a manner similar to
llvm-jitlistener. Currently, we only support the old version of Intel
VTune API.
lhames pushed a commit that referenced this pull request Mar 7, 2024
[ORC] Re-land #81826

This patch adds two plugins: VTuneSupportPlugin.cpp and
JITLoaderVTune.cpp. The testing is done in a manner similar to
llvm-jitlistener. Currently, we only support the old version of Intel
VTune API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants