Skip to content

Commit b3b06fc

Browse files
committed
[SYCL] Implement initial host_pipe registration
What is this for: pipes expose the concept of a first in first out buffer, this FIFO construct provide link between elements of a design that are accessed through read/write/push/pop APIs. A host pipe is a pipe that links a device kernel with host program. This extension is framed from FPGA perspective. This change add required interface for the integration footer to register the `host_pipe` of a program as well as reading extended info supplied through "SYCL/host pipes" property. Info is stored in a map managed by program manager. The integration header and footer provides a mapping from the host address of each pipe variable to the unique string for that variable. This is required so that sycl runtime can query the pipe address from the given pipe name, and pass both into opencl runtime function calls. Opencl defines pipes, which are FIFO constructs that are consistent with Khronos specification. Spec link: #5838 List of suported properties: #5839 Note: it is the first change to runtime relating to host_pipe, thus the feature is not complete / fully testable. It is intended to add an interface for integration footer as well as consumer for the information sycl-post-link will be generating when future work is added.
1 parent 769851c commit b3b06fc

File tree

12 files changed

+195
-0
lines changed

12 files changed

+195
-0
lines changed

llvm/include/llvm/Support/PropertySetIO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class PropertySetRegistry {
193193
static constexpr char SYCL_ASSERT_USED[] = "SYCL/assert used";
194194
static constexpr char SYCL_EXPORTED_SYMBOLS[] = "SYCL/exported symbols";
195195
static constexpr char SYCL_DEVICE_GLOBALS[] = "SYCL/device globals";
196+
static constexpr char SYCL_HOST_PIPES[] = "SYCL/host pipes";
196197

197198
// Function for bulk addition of an entire property set under given category
198199
// (property set name).

llvm/lib/Support/PropertySetIO.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ constexpr char PropertySetRegistry::SYCL_MISC_PROP[];
202202
constexpr char PropertySetRegistry::SYCL_ASSERT_USED[];
203203
constexpr char PropertySetRegistry::SYCL_EXPORTED_SYMBOLS[];
204204
constexpr char PropertySetRegistry::SYCL_DEVICE_GLOBALS[];
205+
constexpr char PropertySetRegistry::SYCL_HOST_PIPES[];
205206

206207
} // namespace util
207208
} // namespace llvm
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//==-------------------- host_pipe_map.hpp -----------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
__SYCL_INLINE_NAMESPACE(cl) {
12+
namespace sycl {
13+
namespace detail {
14+
namespace host_pipe_map {
15+
16+
__SYCL_EXPORT void add(const void *HostPipePtr, const char *UniqueId);
17+
18+
} // namespace host_pipe_map
19+
} // namespace detail
20+
} // namespace sycl
21+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/detail/pi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ static const uint8_t PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL = 4;
777777
#define __SYCL_PI_PROPERTY_SET_SYCL_EXPORTED_SYMBOLS "SYCL/exported symbols"
778778
/// PropertySetRegistry::SYCL_DEVICE_GLOBALS defined in PropertySetIO.h
779779
#define __SYCL_PI_PROPERTY_SET_SYCL_DEVICE_GLOBALS "SYCL/device globals"
780+
/// PropertySetRegistry::SYCL_HOST_PIPES defined in PropertySetIO.h
781+
#define __SYCL_PI_PROPERTY_SET_SYCL_HOST_PIPES "SYCL/host pipes"
780782

781783
/// Program metadata tags recognized by the PI backends. For kernels the tag
782784
/// must appear after the kernel name.

sycl/include/CL/sycl/detail/pi.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ class DeviceBinaryImage {
383383
DeviceGlobals.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_DEVICE_GLOBALS);
384384
return DeviceGlobals;
385385
}
386+
const PropertyRange getHostPipes() const {
387+
// We can't have this variable as a class member, since it would break
388+
// the ABI backwards compatibility.
389+
DeviceBinaryImage::PropertyRange HostPipes;
390+
HostPipes.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_HOST_PIPES);
391+
return HostPipes;
392+
}
386393
virtual ~DeviceBinaryImage() {}
387394

388395
protected:

sycl/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ set(SYCL_SOURCES
134134
"detail/context_impl.cpp"
135135
"detail/device_binary_image.cpp"
136136
"detail/device_filter.cpp"
137+
"detail/host_pipe_map.cpp"
137138
"detail/device_global_map.cpp"
138139
"detail/device_impl.cpp"
139140
"detail/error_handling/enqueue_kernel.cpp"

sycl/source/detail/host_pipe_map.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//==-------------------- host_pipe_map.cpp -----------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <detail/program_manager/program_manager.hpp>
10+
11+
__SYCL_INLINE_NAMESPACE(cl) {
12+
namespace sycl {
13+
namespace detail {
14+
namespace host_pipe_map {
15+
16+
__SYCL_EXPORT void add(const void *HostPipePtr, const char *UniqueId) {
17+
detail::ProgramManager::getInstance().addOrInitHostPipeEntry(HostPipePtr,
18+
UniqueId);
19+
}
20+
21+
} // namespace host_pipe_map
22+
} // namespace detail
23+
} // namespace sycl
24+
} // __SYCL_INLINE_NAMESPACE(cl)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//==----------------- host_pipe_map_entry.hpp --------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <cstdint>
12+
#include <unordered_map>
13+
14+
__SYCL_INLINE_NAMESPACE(cl) {
15+
namespace sycl {
16+
namespace detail {
17+
18+
struct HostPipeMapEntry {
19+
std::string MUniqueId;
20+
// Pointer to the host_pipe on host.
21+
const void *MHostPipePtr;
22+
// Size of the underlying type in the host_pipe.
23+
std::uint32_t MHostPipeTSize;
24+
25+
// Constructor only initializes with the pointer and ID.
26+
// Other members will be initialized later
27+
HostPipeMapEntry(std::string UniqueId, const void *HostPipePtr)
28+
: MUniqueId(UniqueId), MHostPipePtr(HostPipePtr), MHostPipeTSize(0) {}
29+
30+
// Constructor only initializes with the size and ID.
31+
// Other members will be initialized later
32+
HostPipeMapEntry(std::string UniqueId, std::uint32_t HostPipeTSize)
33+
: MUniqueId(UniqueId), MHostPipePtr(nullptr),
34+
MHostPipeTSize(HostPipeTSize) {}
35+
36+
void initialize(std::uint32_t HostPipeTSize) {
37+
assert(HostPipeTSize != 0 && "Host pipe initialized with 0 size.");
38+
assert(MHostPipeTSize == 0 && "Host pipe has already been initialized.");
39+
MHostPipeTSize = HostPipeTSize;
40+
}
41+
42+
void initialize(const void *HostPipePtr) {
43+
assert(!MHostPipePtr && "Host pipe pointer has already been initialized.");
44+
MHostPipePtr = HostPipePtr;
45+
}
46+
};
47+
48+
} // namespace detail
49+
} // namespace sycl
50+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,40 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) {
12201220
Entry->second.initialize(TypeSize, DeviceImageScopeDecorated);
12211221
}
12221222
}
1223+
// ... and initialize associated host_pipe information
1224+
{
1225+
std::lock_guard HostPipesGuard(m_HostPipesMutex);
1226+
1227+
auto HostPipes = Img->getHostPipes();
1228+
for (const pi_device_binary_property &HostPipe : HostPipes) {
1229+
pi::ByteArray HostPipeInfo =
1230+
pi::DeviceBinaryProperty(HostPipe).asByteArray();
1231+
1232+
// The supplied host_pipe info property is expected to contain:
1233+
// * 8 bytes - Size of the property.
1234+
// * 4 bytes - Size of the underlying type in the host_pipe.
1235+
// Note: Property may be padded.
1236+
constexpr unsigned int NumPropertySizeBytes = 8;
1237+
constexpr unsigned int NumTypeBytes = 4;
1238+
assert(HostPipeInfo.size() >= NumPropertySizeBytes + NumTypeBytes &&
1239+
"Unexpected property size");
1240+
auto TypeSize = *reinterpret_cast<const std::uint32_t *>(
1241+
&HostPipeInfo[NumPropertySizeBytes]);
1242+
1243+
auto ExistingHostPipe = m_HostPipes.find(HostPipe->Name);
1244+
if (ExistingHostPipe != m_HostPipes.end()) {
1245+
// If it has already been registered we update the information.
1246+
ExistingHostPipe->second->initialize(TypeSize);
1247+
} else {
1248+
// If it has not already been registered we create a new entry.
1249+
// Note: Pointer to the host pipe is not available here, so it
1250+
// cannot be set until registration happens.
1251+
auto EntryUPtr =
1252+
std::make_unique<HostPipeMapEntry>(HostPipe->Name, TypeSize);
1253+
m_HostPipes.emplace(HostPipe->Name, std::move(EntryUPtr));
1254+
}
1255+
}
1256+
}
12231257
m_DeviceImages[KSId].reset(new std::vector<RTDeviceBinaryImageUPtr>());
12241258

12251259
cacheKernelUsesAssertInfo(M, *Img);
@@ -1469,6 +1503,36 @@ kernel_id ProgramManager::getBuiltInKernelID(const std::string &KernelName) {
14691503
return KernelID->second;
14701504
}
14711505

1506+
void ProgramManager::addOrInitHostPipeEntry(const void *HostPipePtr,
1507+
const char *UniqueId) {
1508+
std::lock_guard<std::mutex> HostPipesGuard(m_HostPipesMutex);
1509+
1510+
auto ExistingHostPipe = m_HostPipes.find(UniqueId);
1511+
if (ExistingHostPipe != m_HostPipes.end()) {
1512+
ExistingHostPipe->second->initialize(HostPipePtr);
1513+
m_Ptr2HostPipe.insert({HostPipePtr, ExistingHostPipe->second.get()});
1514+
return;
1515+
}
1516+
auto EntryUPtr = std::make_unique<HostPipeMapEntry>(UniqueId, HostPipePtr);
1517+
auto NewEntry = m_HostPipes.emplace(UniqueId, std::move(EntryUPtr));
1518+
m_Ptr2HostPipe.insert({HostPipePtr, NewEntry.first->second.get()});
1519+
}
1520+
1521+
HostPipeMapEntry *
1522+
ProgramManager::getHostPipeEntry(const std::string &UniqueId) {
1523+
std::lock_guard<std::mutex> HostPipesGuard(m_HostPipesMutex);
1524+
auto Entry = m_HostPipes.find(UniqueId);
1525+
assert(Entry != m_HostPipes.end() && "Host pipe entry not found");
1526+
return Entry->second.get();
1527+
}
1528+
1529+
HostPipeMapEntry *ProgramManager::getHostPipeEntry(const void *HostPipePtr) {
1530+
std::lock_guard<std::mutex> HostPipesGuard(m_HostPipesMutex);
1531+
auto Entry = m_Ptr2HostPipe.find(HostPipePtr);
1532+
assert(Entry != m_Ptr2HostPipe.end() && "Host pipe entry not found");
1533+
return Entry->second;
1534+
}
1535+
14721536
void ProgramManager::addDeviceGlobalEntry(void *DeviceGlobalPtr,
14731537
const char *UniqueId) {
14741538
std::lock_guard<std::mutex> DeviceGlobalsGuard(m_DeviceGlobalsMutex);

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
#include <CL/sycl/detail/common.hpp>
1111
#include <CL/sycl/detail/device_binary_image.hpp>
1212
#include <CL/sycl/detail/export.hpp>
13+
#include <CL/sycl/detail/host_pipe_map.hpp>
1314
#include <CL/sycl/detail/os_util.hpp>
1415
#include <CL/sycl/detail/pi.hpp>
1516
#include <CL/sycl/detail/util.hpp>
1617
#include <CL/sycl/device.hpp>
1718
#include <CL/sycl/kernel_bundle.hpp>
1819
#include <CL/sycl/stl.hpp>
1920
#include <detail/device_global_map_entry.hpp>
21+
#include <detail/host_pipe_map_entry.hpp>
2022
#include <detail/spec_constant_impl.hpp>
2123

2224
#include <cstdint>
@@ -183,6 +185,18 @@ class ProgramManager {
183185
// built-in kernel name.
184186
kernel_id getBuiltInKernelID(const std::string &KernelName);
185187

188+
// The function inserts or initializes a host_pipe entry into the
189+
// host_pipe map.
190+
void addOrInitHostPipeEntry(const void *HostPipePtr, const char *UniqueId);
191+
192+
// The function gets a host_pipe entry identified by the unique ID from
193+
// the host_pipe map.
194+
HostPipeMapEntry *getHostPipeEntry(const std::string &UniqueId);
195+
196+
// The function gets a host_pipe entry identified by the pointer to the
197+
// host_pipe object from the host_pipe map.
198+
HostPipeMapEntry *getHostPipeEntry(const void *HostPipePtr);
199+
186200
// The function inserts a device_global entry into the device_global map.
187201
void addDeviceGlobalEntry(void *DeviceGlobalPtr, const char *UniqueId);
188202

@@ -392,6 +406,14 @@ class ProgramManager {
392406

393407
/// Protects m_DeviceGlobals.
394408
std::mutex m_DeviceGlobalsMutex;
409+
410+
// Maps between host_pipe identifiers and associated information.
411+
std::unordered_map<std::string, std::unique_ptr<HostPipeMapEntry>>
412+
m_HostPipes;
413+
std::unordered_map<const void *, HostPipeMapEntry *> m_Ptr2HostPipe;
414+
415+
/// Protects m_HostPipes and m_Ptr2HostPipe.
416+
std::mutex m_HostPipesMutex;
395417
};
396418
} // namespace detail
397419
} // namespace sycl

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,6 +3881,7 @@ _ZN2cl4sycl6detail13MemoryManager8copy_usmEPKvSt10shared_ptrINS1_10queue_implEEm
38813881
_ZN2cl4sycl6detail13MemoryManager8copy_usmEPKvSt10shared_ptrINS1_10queue_implEEmPvSt6vectorIP9_pi_eventSaISB_EERSB_
38823882
_ZN2cl4sycl6detail13MemoryManager8fill_usmEPvSt10shared_ptrINS1_10queue_implEEmiSt6vectorIP9_pi_eventSaIS9_EEPS9_
38833883
_ZN2cl4sycl6detail13MemoryManager8fill_usmEPvSt10shared_ptrINS1_10queue_implEEmiSt6vectorIP9_pi_eventSaIS9_EERS9_
3884+
_ZN2cl4sycl6detail13host_pipe_map3addEPKvPKc
38843885
_ZN2cl4sycl6detail13make_platformEmNS0_7backendE
38853886
_ZN2cl4sycl6detail14getBorderColorENS0_19image_channel_orderE
38863887
_ZN2cl4sycl6detail14host_half_impl4halfC1ERKf

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,7 @@
10901090
?acospi@__host_std@cl@@YA?AVhalf@half_impl@detail@sycl@2@V34562@@Z
10911091
?acospi@__host_std@cl@@YAMM@Z
10921092
?acospi@__host_std@cl@@YANN@Z
1093+
?add@host_pipe_map@detail@sycl@cl@@YAXPEBXPEBD@Z
10931094
?addHostAccessorAndWait@detail@sycl@cl@@YAXPEAVAccessorImplHost@123@@Z
10941095
?addOrReplaceAccessorProperties@SYCLMemObjT@detail@sycl@cl@@QEAAXAEBVproperty_list@34@@Z
10951096
?addReduction@handler@sycl@cl@@AEAAXAEBV?$shared_ptr@$$CBX@std@@@Z

0 commit comments

Comments
 (0)