Skip to content

Commit 8d3921e

Browse files
author
Alexander Batashev
authored
[SYCL] Enable ITT notification support in SYCL Runtime (#3832)
1 parent 7e296d6 commit 8d3921e

File tree

8 files changed

+345
-1
lines changed

8 files changed

+345
-1
lines changed

sycl/source/detail/config.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ CONFIG(SYCL_CACHE_MAX_SIZE, 16, __SYCL_CACHE_MAX_SIZE)
2929
CONFIG(SYCL_CACHE_THRESHOLD, 16, __SYCL_CACHE_THRESHOLD)
3030
CONFIG(SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE, 16, __SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE)
3131
CONFIG(SYCL_CACHE_MAX_DEVICE_IMAGE_SIZE, 16, __SYCL_CACHE_MAX_DEVICE_IMAGE_SIZE)
32+
CONFIG(INTEL_ENABLE_OFFLOAD_ANNOTATIONS, 1, __SYCL_INTEL_ENABLE_OFFLOAD_ANNOTATIONS)

sycl/source/detail/config.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,15 @@ template <ConfigID Config> class SYCLConfig {
102102
using BaseT = SYCLConfigBase<Config>;
103103

104104
public:
105-
static const char *get() {
105+
static const char *get() { return getCachedValue(); }
106+
107+
static void reset() { (void)getCachedValue(/*ResetCache=*/true); }
108+
109+
private:
110+
static const char *getCachedValue(bool ResetCache = false) {
106111
static const char *ValStr = BaseT::getRawValue();
112+
if (ResetCache)
113+
ValStr = BaseT::getRawValue();
107114
return ValStr;
108115
}
109116
};

sycl/source/detail/persistent_device_code_cache.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <detail/device_impl.hpp>
1111
#include <detail/persistent_device_code_cache.hpp>
1212
#include <detail/plugin.hpp>
13+
#include <detail/program_manager/program_manager.hpp>
1314

1415
#if defined(__SYCL_RT_OS_LINUX)
1516
#include <unistd.h>
@@ -51,6 +52,11 @@ bool PersistentDeviceCodeCache::isImageCached(const RTDeviceBinaryImage &Img) {
5152
if (!isEnabled() || Img.getFormat() != PI_DEVICE_BINARY_TYPE_SPIRV)
5253
return false;
5354

55+
// Disable cache for ITT-profiled images.
56+
if (SYCLConfig<INTEL_ENABLE_OFFLOAD_ANNOTATIONS>::get()) {
57+
return false;
58+
}
59+
5460
static auto MaxImgSize = getNumParam<SYCL_CACHE_MAX_DEVICE_IMAGE_SIZE>(
5561
DEFAULT_MAX_DEVICE_IMAGE_SIZE);
5662
static auto MinImgSize = getNumParam<SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE>(

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ enum BuildState { BS_InProgress, BS_Done, BS_Failed };
4949

5050
static constexpr char UseSpvEnv[]("SYCL_USE_KERNEL_SPV");
5151

52+
/// This function enables ITT annotations in SPIR-V module by setting
53+
/// a specialization constant if INTEL_LIBITTNOTIFY64 env variable is set.
54+
static void enableITTAnnotationsIfNeeded(const RT::PiProgram &Prog,
55+
const plugin &Plugin) {
56+
if (SYCLConfig<INTEL_ENABLE_OFFLOAD_ANNOTATIONS>::get() != nullptr) {
57+
constexpr char SpecValue = 1;
58+
Plugin.call<PiApiKind::piextProgramSetSpecializationConstant>(
59+
Prog, ITTSpecConstId, sizeof(char), &SpecValue);
60+
}
61+
}
62+
5263
ProgramManager &ProgramManager::getInstance() {
5364
return GlobalHandler::instance().getProgramManager();
5465
}
@@ -453,6 +464,9 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
453464
NativePrg = createPIProgram(Img, Context, Device);
454465
if (Prg)
455466
flushSpecConstants(*Prg, NativePrg, &Img);
467+
if (Img.supportsSpecConstants())
468+
enableITTAnnotationsIfNeeded(NativePrg,
469+
getSyclObjImpl(Device)->getPlugin());
456470
}
457471

458472
ProgramPtr ProgramManaged(
@@ -1421,6 +1435,10 @@ ProgramManager::compile(const device_image_plain &DeviceImage,
14211435
RT::PiProgram Prog = createPIProgram(*InputImpl->get_bin_image_ref(),
14221436
InputImpl->get_context(), Devs[0]);
14231437

1438+
for (const device &Dev : Devs)
1439+
if (InputImpl->get_bin_image_ref()->supportsSpecConstants())
1440+
enableITTAnnotationsIfNeeded(Prog, getSyclObjImpl(Dev)->getPlugin());
1441+
14241442
DeviceImageImplPtr ObjectImpl = std::make_shared<detail::device_image_impl>(
14251443
InputImpl->get_bin_image_ref(), InputImpl->get_context(), Devs,
14261444
bundle_state::object, InputImpl->get_kernel_ids_ref(), Prog,
@@ -1561,6 +1579,11 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
15611579
// device is OK.
15621580
RT::PiProgram NativePrg = createPIProgram(Img, Context, Devs[0]);
15631581

1582+
for (const device &Dev : Devs)
1583+
if (InputImpl->get_bin_image_ref()->supportsSpecConstants())
1584+
enableITTAnnotationsIfNeeded(NativePrg,
1585+
getSyclObjImpl(Dev)->getPlugin());
1586+
15641587
const std::vector<unsigned char> &SpecConstsBlob =
15651588
InputImpl->get_spec_const_blob_ref();
15661589

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ namespace sycl {
4242
class context;
4343
namespace detail {
4444

45+
// This value must be the same as in libdevice/device_itt.h.
46+
// See sycl/doc/extensions/ITTAnnotations/ITTAnnotations.rst for more info.
47+
static constexpr uint32_t inline ITTSpecConstId = 0xFF747469;
48+
4549
class context_impl;
4650
using ContextImplPtr = std::shared_ptr<context_impl>;
4751
class program_impl;

sycl/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ add_subdirectory(queue)
1818
add_subdirectory(scheduler)
1919
add_subdirectory(spec_constants)
2020
add_subdirectory(thread_safety)
21+
add_subdirectory(program_manager)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(CMAKE_CXX_EXTENSIONS OFF)
2+
3+
# Enable exception handling for these unit tests
4+
set(LLVM_REQUIRES_EH 1)
5+
add_sycl_unittest(ProgramManagerTests OBJECT
6+
itt_annotations.cpp
7+
)
8+

0 commit comments

Comments
 (0)