Skip to content

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

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

Merged
merged 6 commits into from
Mar 7, 2024

Conversation

hongyu-dev
Copy link
Contributor

This patch relands #81826

Note to reviewers: I split this pull requests in two commits. One for reland #81826 and the other one for fixing #83909. I'll squash those two into one once they are ready to be merged.

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 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.
@hongyu-dev
Copy link
Contributor Author

@MaskRay @lhames Could you guys help me to review this? Thank you!

Copy link

github-actions bot commented Mar 5, 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 564b81db8541468ce296d3bdcacab05b9581297c e7e6d8f4a2e268b633e613a17a4c1d20868e3332 -- llvm/include/llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h llvm/include/llvm/ExecutionEngine/Orc/Shared/VTuneSharedStructs.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 afb7df592f..52b9476947 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h
@@ -27,5 +27,3 @@ extern "C" llvm::orc::shared::CWrapperFunctionResult
 llvm_orc_test_registerVTuneImpl(const char *Data, uint64_t Size);
 
 #endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_JITLOADERVTUNE_H
-
-

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

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

I don't know the code, so I am just commenting on the code style...

ExecutorAddr RegisterVTuneImplAddr;
ExecutorAddr UnregisterVTuneImplAddr;
std::mutex PluginMutex;
uint64_t NextMethodID{0};
Copy link
Member

Choose a reason for hiding this comment

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

nit: = 0

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!

ExecutorAddr UnregisterVTuneImplAddr;
std::mutex PluginMutex;
uint64_t NextMethodID{0};
DenseMap<MaterializationResponsibility *, std::pair<uint64_t, uint64_t>>
Copy link
Member

Choose a reason for hiding this comment

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

include DenseMap for IWYU

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!

VTuneStringTable Strings;
};

typedef std::vector<std::pair<uint64_t, uint64_t>> VTuneUnloadedMethodIDs;
Copy link
Member

Choose a reason for hiding this comment

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

nit: prefer using

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!

using namespace llvm::orc;
using namespace llvm::jitlink;

namespace {
Copy link
Member

Choose a reason for hiding this comment

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

https://llvm.org/docs/CodingStandards.html#anonymous-namespaces

In .cpp, basically anonymous namespaces are only for struct, class, enum, etc.

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!

@@ -2,10 +2,18 @@ if( CMAKE_HOST_UNIX AND HAVE_LIBRT )
set(rt_lib rt)
endif()

set(intel_jit_profiling )
if( LLVM_USE_INTEL_JITEVENTS )
set(intel_jit_profiling IntelJITProfiling)
Copy link
Member

Choose a reason for hiding this comment

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

indent

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~

using namespace llvm;
using namespace llvm::orc;

static std::unique_ptr<IntelJITEventsWrapper> Wrapper;
Copy link
Member

Choose a reason for hiding this comment

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

Can this global variable be placed into a context class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Fangrui, I fixed it into a context class, but I do not see the reason why we need a context class here because Wrapper is only used in JITLoaderVTune.cpp. Could you please elaborate more on it? Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

The idea is to avoid a global state, more preferrable if the state can be shared between multiple threads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! Fixed! Please let me know if there is anything else I need to change.


// For Testing: following code comes from llvm-jitlistener.cpp in llvm tools
namespace {
typedef std::vector<std::pair<std::string, unsigned int>> SourceLocations;
Copy link
Member

Choose a reason for hiding this comment

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

using

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~

@@ -0,0 +1,52 @@
# REQUIRES: native && x86_64-linux && intel-jitevents

# RUN: rm -rf %t && mkdir -p %t
Copy link
Member

Choose a reason for hiding this comment

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

remove -p since the file/directory is guaranteed to be absent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

# REQUIRES: native && x86_64-linux && intel-jitevents

# RUN: rm -rf %t && mkdir -p %t
# RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent \
Copy link
Member

Choose a reason for hiding this comment

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

remove -position-independent. Only mips/sparc use the option for some assembly design flaws.

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!

uint64_t NextMethodID{0};
DenseMap<MaterializationResponsibility *, std::pair<uint64_t, uint64_t>>
PendingMethodIDs;
DenseMap<ResourceKey, std::vector<std::pair<uint64_t, uint64_t>>>
Copy link
Member

Choose a reason for hiding this comment

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

Consider replacing std::vector<X> with SmallVector<X, 0>, since SmallVector is smaller in size and is often more efficient. When used in another container like DenseMap , the advantage of SmallVector is larger.

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 it too!

@MaskRay
Copy link
Member

MaskRay commented Mar 5, 2024

bazel-6.3.2 build --config=generic_clang @llvm-project//llvm:llvm-jitlink passes, so the library layering seems good.

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.

Minor comments aside this looks great. Thank you for resolving the layering issue!

Comment on lines 13 to 14
#ifndef LLVM_EXECUTIONENGINE_ORC_AMPLIFIERSUPPORTPLUGIN_H
#define LLVM_EXECUTIONENGINE_ORC_AMPLIFIERSUPPORTPLUGIN_H
Copy link
Contributor

Choose a reason for hiding this comment

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

The include guards should match the filename -- LLVM_EXECUTIONENGINE_ORC_DEBUGGING_VTUNESUPPORT_H.

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!

} // end namespace orc
} // end namespace llvm

#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing newline.

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!

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.

LGTM! Thanks @yugier!

@lhames lhames merged commit 00f4121 into llvm:main Mar 7, 2024
@hongyu-dev hongyu-dev deleted the VTuneSupportUpstream branch March 14, 2024 04:12
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.

3 participants