Skip to content

Commit 28ba1a2

Browse files
committed
[SYCL] Cache host pipe to device image mapping
To build program before first kernel launch, the program manager requires knowing the device image, device and context associated with a host pipe. It then will take from cache or build the program from device image. This work around the difficulty of program being built on first kernel launch, and allows the host pipe read/write to happen at any point.
1 parent 44b7e73 commit 28ba1a2

File tree

7 files changed

+42
-27
lines changed

7 files changed

+42
-27
lines changed

sycl/include/sycl/ext/intel/experimental/host_pipes.hpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,19 @@ class
5252

5353
struct
5454
#ifdef __SYCL_DEVICE_ONLY__
55-
[[__sycl_detail__::add_ir_global_variable_attributes(
56-
"sycl-host-pipe",
57-
nullptr
58-
)]]
59-
[[__sycl_detail__::host_pipe]]
60-
[[__sycl_detail__::global_variable_allowed]] // may not be needed
55+
[[__sycl_detail__::add_ir_global_variable_attributes(
56+
"sycl-host-pipe",
57+
nullptr)]] [[__sycl_detail__::
58+
host_pipe]] [[__sycl_detail__::
59+
global_variable_allowed]] // may
60+
// not be
61+
// needed
6162
#endif
62-
__pipeType { const char __p; };
63-
64-
static constexpr __pipeType __pipe = {0};
63+
__pipeType {
64+
const char __p;
65+
};
66+
67+
static constexpr __pipeType __pipe = {0};
6568

6669
public:
6770
using value_type = _dataT;

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4123,12 +4123,12 @@ pi_result piProgramGetInfo(pi_program Program, pi_program_info ParamName,
41234123
uint32_t Count = 0;
41244124
ZE_CALL(zeModuleGetKernelNames, (Program->ZeModule, &Count, nullptr));
41254125
std::unique_ptr<const char *[]> PNames(new const char *[Count]);
4126-
ZE_CALL(zeModuleGetKernelNames,
4127-
(Program->ZeModule, &Count, PNames.get()));
4128-
for (uint32_t I = 0; I < Count; ++I) {
4129-
PINames += (I > 0 ? ";" : "");
4130-
PINames += PNames[I];
4131-
}
4126+
ZE_CALL(zeModuleGetKernelNames,
4127+
(Program->ZeModule, &Count, PNames.get()));
4128+
for (uint32_t I = 0; I < Count; ++I) {
4129+
PINames += (I > 0 ? ";" : "");
4130+
PINames += PNames[I];
4131+
}
41324132
} else {
41334133
return PI_INVALID_PROGRAM;
41344134
}

sycl/source/detail/host_pipe.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <sycl/ext/intel/experimental/host_pipes.hpp>
109
#include <detail/host_pipe_map_entry.hpp>
1110
#include <detail/program_manager/program_manager.hpp>
11+
#include <sycl/ext/intel/experimental/host_pipes.hpp>
1212

1313
__SYCL_INLINE_NAMESPACE(cl) {
1414
namespace sycl {
@@ -29,9 +29,10 @@ host_pipe<_name, _dataT, _propertiesT,
2929
}
3030
// TODO: get pipe name from the pipe registration
3131
_dataT data;
32-
const void* HostPipePtr = &__pipe;
33-
detail::HostPipeMapEntry hostPipeEntry = detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr);
34-
const std::string pipe_name = hostPipeEntry.MUniqueId;
32+
const void *HostPipePtr = &__pipe;
33+
detail::HostPipeMapEntry *hostPipeEntry =
34+
detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr);
35+
const std::string pipe_name = hostPipeEntry->MUniqueId;
3536
size_t size = 4;
3637
event e = q.submit([=](handler &CGH) {
3738
CGH.read_write_host_pipe(pipe_name, (void *)(&data), (size_t)size, false,
@@ -54,9 +55,10 @@ void host_pipe<
5455
return;
5556
}
5657
// TODO: get pipe name from the pipe registration
57-
const void* HostPipePtr = &__pipe;
58-
detail::HostPipeMapEntry hostPipeEntry = detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr);
59-
const std::string pipe_name = hostPipeEntry.MUniqueId;
58+
const void *HostPipePtr = &__pipe;
59+
detail::HostPipeMapEntry *hostPipeEntry =
60+
detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr);
61+
const std::string pipe_name = hostPipeEntry->MUniqueId;
6062
const void *data_ptr = &data;
6163
size_t size = 4;
6264
event e = q.submit([=](handler &CGH) {

sycl/source/detail/host_pipe_map_entry.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <CL/sycl/detail/device_binary_image.hpp>
1112
#include <cstdint>
1213
#include <unordered_map>
1314

@@ -21,6 +22,8 @@ struct HostPipeMapEntry {
2122
const void *MHostPipePtr;
2223
// Size of the underlying type in the host_pipe.
2324
std::uint32_t MHostPipeTSize;
25+
// The device image that pipe is associated with
26+
const RTDeviceBinaryImage *mDeviceImage;
2427

2528
// Constructor only initializes with the pointer and ID.
2629
// Other members will be initialized later
@@ -43,6 +46,9 @@ struct HostPipeMapEntry {
4346
assert(!MHostPipePtr && "Host pipe pointer has already been initialized.");
4447
MHostPipePtr = HostPipePtr;
4548
}
49+
void initialize(const RTDeviceBinaryImage *DeviceImage) {
50+
mDeviceImage = DeviceImage;
51+
}
4652
};
4753

4854
} // namespace detail

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,12 +1253,14 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) {
12531253
if (ExistingHostPipe != m_HostPipes.end()) {
12541254
// If it has already been registered we update the information.
12551255
ExistingHostPipe->second->initialize(TypeSize);
1256+
ExistingHostPipe->second->initialize(Img.get());
12561257
} else {
12571258
// If it has not already been registered we create a new entry.
12581259
// Note: Pointer to the host pipe is not available here, so it
12591260
// cannot be set until registration happens.
12601261
auto EntryUPtr =
12611262
std::make_unique<HostPipeMapEntry>(HostPipe->Name, TypeSize);
1263+
EntryUPtr->initialize(Img.get());
12621264
m_HostPipes.emplace(HostPipe->Name, std::move(EntryUPtr));
12631265
}
12641266
}

sycl/source/detail/scheduler/commands.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <CL/sycl/sampler.hpp>
1919
#include <detail/context_impl.hpp>
2020
#include <detail/event_impl.hpp>
21+
#include <detail/host_pipe_map_entry.hpp>
2122
#include <detail/kernel_bundle_impl.hpp>
2223
#include <detail/kernel_impl.hpp>
2324
#include <detail/kernel_info.hpp>
@@ -2201,12 +2202,12 @@ cl_uint enqueueReadWriteHostPipe(const QueueImplPtr &Queue,
22012202
// 1. Encode this in the pipe registration
22022203
// 2. Initialize the pipe registration from first kernel launch, but then this
22032204
// will violate the spec
2204-
detail::OSModuleHandle M =
2205-
detail::OSUtil::getOSModuleHandle("HostPipeReadWriteKernelName");
2205+
detail::HostPipeMapEntry *hostPipeEntry =
2206+
detail::ProgramManager::getInstance().getHostPipeEntry(PipeName);
22062207
RT::PiProgram Program =
2207-
sycl::detail::ProgramManager::getInstance().getBuiltPIProgram(
2208-
M, Queue->getContextImplPtr(), Queue->getDeviceImplPtr(),
2209-
"HostPipeReadWriteKernelName");
2208+
sycl::detail::ProgramManager::getInstance().createPIProgram(
2209+
*(hostPipeEntry->mDeviceImage), Queue->get_context(),
2210+
Queue->get_device());
22102211

22112212
// Get plugin for calling opencl functions
22122213
const detail::plugin &Plugin = Queue->getPlugin();

sycl/test/abi/layout_handler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s
12
// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
23
// REQUIRES: linux
34
// UNSUPPORTED: libcxx

0 commit comments

Comments
 (0)