Skip to content

[SYCL] Host pipe runtime implementation #7468

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 59 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ac2e0a3
[SYCL] Implement initial host_pipe registration
sherry-yuan Nov 21, 2022
8e054e2
Add pi extension API for host pipes
sherry-yuan Mar 24, 2022
0fc3879
[SYCL] Add new hostpipe API to PIMockPlugin
zibaiwan Nov 23, 2022
44342a6
[SYCL] Add data_flow_pipe properties
sherry-yuan Nov 23, 2022
4e816d8
Register new command group to execute host pipe read/write operation
sherry-yuan Mar 25, 2022
abbb0a3
[SYCL] fix layout handler
zibaiwan Nov 28, 2022
aa6cdff
[SYCL] Query pipe name from registration
sherry-yuan Mar 30, 2022
0d95375
[SYCL] Cache host pipe to device image mapping
zibaiwan Nov 28, 2022
26eec1a
[SYCL][UNITTEST] Unit testing host pipe functionality
sherry-yuan Apr 19, 2022
6d98b5a
[SYCL] update unit test to use newer PiMock
zibaiwan Nov 28, 2022
252b403
remove type trait
sherry-yuan Apr 21, 2022
2821aae
Move host pipe additions into existing pipe class
rho180 Jan 20, 2023
8fd64af
Define m_Storage on host and make public
rho180 Jan 31, 2023
5bb9cd6
created templateless base class for pipes
zibaiwan Feb 13, 2023
e2c5b86
Preliminary implementation of host pipe size property
rho180 Feb 27, 2023
c43b3c1
fix blocking read and add API for nonblocking read&write
zibaiwan Mar 6, 2023
714d25d
fixup
zibaiwan Mar 13, 2023
a1d422a
fixup
zibaiwan Mar 14, 2023
a303464
fixup
zibaiwan Mar 14, 2023
104e234
fixup
zibaiwan Mar 14, 2023
3d164e8
clang format fixup
zibaiwan Mar 15, 2023
61fbe0c
fix unit tests
zibaiwan Mar 15, 2023
5791403
run clang format
zibaiwan Mar 15, 2023
ab0fafa
fix pipe property test
zibaiwan Mar 15, 2023
d0fb7d7
Collect host pipe attribute functions and cleanup comments
rho180 Mar 15, 2023
9884770
code cleanup
zibaiwan Mar 15, 2023
d341a8b
update opencl header function pointer name
zibaiwan Mar 16, 2023
6af1f96
Fix misnamed attribute in host pipe lit test
rho180 Mar 16, 2023
d393163
add __SYCL_EXPORT to the header as well
zibaiwan Mar 16, 2023
ac93ebf
update windows symbol dump
zibaiwan Mar 16, 2023
30eace1
Updated default value for the pipe properties
zibaiwan Mar 18, 2023
cade651
fixup
zibaiwan Mar 20, 2023
ae0988b
Update OPENCL Header commit
zibaiwan Mar 21, 2023
a41263a
Comments fixup
zibaiwan Mar 21, 2023
7878b26
Update error messages when the device side API is called on the host
zibaiwan Mar 21, 2023
ddcc067
fix error messages
zibaiwan Mar 21, 2023
400a10a
update default value of bits per symbol to 8
zibaiwan Mar 24, 2023
666af1c
various fixes and style changes
zibaiwan Mar 24, 2023
1b6db48
Variable naming style change
zibaiwan Mar 26, 2023
2c6f27d
Reuse unique id attribute function from device globals for host pipes
rho180 Mar 27, 2023
3a49068
Update PI version and run clang format
zibaiwan Mar 27, 2023
21298fc
Merge branch 'sycl' into sycl-hostpipe-runtime
zibaiwan Mar 27, 2023
a339956
clang-format change
zibaiwan Mar 27, 2023
80c57d5
seperate handler function into read and write functions
zibaiwan Mar 28, 2023
3c2ed1c
make the new handler member private
zibaiwan Mar 28, 2023
873b385
Merge branch 'sycl' into sycl-hostpipe-runtime
zibaiwan Mar 28, 2023
66a6307
Fix Pipe unit test to be able access private handler function
zibaiwan Mar 29, 2023
a9c58f6
fix windows symbol dump
zibaiwan Mar 29, 2023
e4ff9a4
fix unit test to call pipe read/write directly
zibaiwan Mar 29, 2023
15136a6
run clang format
zibaiwan Mar 29, 2023
8478af2
Merge branch 'intel:sycl' into sycl-hostpipe-runtime
zibaiwan Mar 29, 2023
6913660
Empty commit
zibaiwan Mar 29, 2023
39ab2b9
fixup
zibaiwan Mar 29, 2023
05a7dff
fixup const qualifier
zibaiwan Mar 29, 2023
bcec635
remove unnecessary cast
zibaiwan Mar 29, 2023
979201a
fixup the const cast
zibaiwan Mar 29, 2023
839d7ee
fix the default switch in the unittest
zibaiwan Mar 29, 2023
0b2ebd2
Empty commit to try triggering CI
zibaiwan Mar 29, 2023
302aa86
Empty commit to try triggering CI
zibaiwan Mar 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildbot/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def do_dependency(args):

# Checkout fixed version to avoid unexpected issues coming from upstream
# Specific version can be uplifted as soon as such need arise
checkout_cmd = ["git", "checkout", "23710f1b99186065c1768fc3098ba681adc0f253"]
checkout_cmd = ["git", "checkout", "9ddb236e6eb3cf844f9e2f81677e1045f9bf838e"]
subprocess.check_call(checkout_cmd, cwd=ocl_header_dir)

# fetch and build OpenCL ICD loader
Expand Down
59 changes: 59 additions & 0 deletions llvm/include/llvm/SYCLLowerIR/HostPipes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//===------- HostPipes.h - get required info about FPGA Host Pipes --------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// The file contains a number of functions to extract corresponding attributes
// of the host pipe global variables and save them as a property set for the
// runtime.
//===----------------------------------------------------------------------===//

#pragma once

#include "llvm/ADT/MapVector.h"

#include <cstdint>
#include <vector>

namespace llvm {

class GlobalVariable;
class Module;
class StringRef;

// Represents a host pipe variable - at SYCL RT level host pipe
// variables are being represented as a byte-array.
struct HostPipeProperty {
HostPipeProperty(uint32_t Size) : Size(Size) {}

// Encodes size of the underlying type T of the host pipe variable.
uint32_t Size;
};

using HostPipePropertyMapTy =
MapVector<StringRef, std::vector<HostPipeProperty>>;

/// Return \c true if the variable @GV is a host pipe variable.
///
/// The function checks whether the variable has the LLVM IR attribute \c
/// sycl-host-pipe
/// @param GV [in] A variable to test.
///
/// @return \c true if the variable is a host pipe variable, \c false
/// otherwise.
bool isHostPipeVariable(const GlobalVariable &GV);

/// Searches given module for occurrences of host pipe variable-specific
/// metadata and builds "host pipe variable name" ->
/// vector<"variable properties"> map.
///
/// @param M [in] LLVM Module.
///
/// @returns the "host pipe variable name" -> vector<"variable properties">
/// map.
HostPipePropertyMapTy collectHostPipeProperties(const Module &M);

} // end namespace llvm
5 changes: 0 additions & 5 deletions llvm/include/llvm/SYCLLowerIR/SYCLUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace llvm {
namespace sycl {
namespace utils {
constexpr char ATTR_SYCL_MODULE_ID[] = "sycl-module-id";
constexpr StringRef SYCL_HOST_PIPE_ATTR = "sycl-host-pipe";

using CallGraphNodeAction = ::std::function<void(Function *)>;
using CallGraphFunctionFilter =
Expand Down Expand Up @@ -117,10 +116,6 @@ inline bool isSYCLExternalFunction(const Function *F) {
return F->hasFnAttribute(ATTR_SYCL_MODULE_ID);
}

inline bool isHostPipeVariable(const GlobalVariable &GV) {
return GV.hasAttribute(SYCL_HOST_PIPE_ATTR);
}

} // namespace utils
} // namespace sycl
} // namespace llvm
1 change: 1 addition & 0 deletions llvm/include/llvm/Support/PropertySetIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class PropertySetRegistry {
static constexpr char SYCL_EXPORTED_SYMBOLS[] = "SYCL/exported symbols";
static constexpr char SYCL_DEVICE_GLOBALS[] = "SYCL/device globals";
static constexpr char SYCL_DEVICE_REQUIREMENTS[] = "SYCL/device requirements";
static constexpr char SYCL_HOST_PIPES[] = "SYCL/host pipes";

// Function for bulk addition of an entire property set under given category
// (property set name).
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/SYCLLowerIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ add_llvm_component_library(LLVMSYCLLowerIR
ESIMD/LowerESIMDVecArg.cpp
ESIMD/LowerESIMDVLoadVStore.cpp
ESIMD/LowerESIMDSlmReservation.cpp
HostPipes.cpp
LowerInvokeSimd.cpp
LowerKernelProps.cpp
LowerWGLocalMemory.cpp
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "llvm/SYCLLowerIR/CompileTimePropertiesPass.h"
#include "llvm/SYCLLowerIR/DeviceGlobals.h"
#include "llvm/SYCLLowerIR/SYCLUtils.h"
#include "llvm/SYCLLowerIR/HostPipes.h"

#include "llvm/ADT/APInt.h"
#include "llvm/ADT/StringMap.h"
Expand Down Expand Up @@ -343,7 +343,7 @@ PreservedAnalyses CompileTimePropertiesPass::run(Module &M,
HostAccessDecorValue, VarName));
}

if (sycl::utils::isHostPipeVariable(GV)) {
if (isHostPipeVariable(GV)) {
auto VarName = getGlobalVariableUniqueId(GV);
MDOps.push_back(buildSpirvDecorMetadata(Ctx, SPIRV_HOST_ACCESS_DECOR,
SPIRV_HOST_ACCESS_DEFAULT_VALUE,
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/SYCLLowerIR/DeviceGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ bool hasDeviceImageScopeProperty(const GlobalVariable &GV) {
return hasProperty(GV, SYCL_DEVICE_IMAGE_SCOPE_ATTR);
}

/// Returns the unique id for the device global variable.
/// Returns the unique id for the device global or host pipe variable.
///
/// The function gets this value from the LLVM IR attribute \c
/// sycl-unique-id.
///
/// @param GV [in] Device Global variable.
/// @param GV [in] Device Global or Hostpipe variable.
///
/// @returns the unique id of the device global variable represented
/// in the LLVM IR by \c GV.
/// @returns the unique id of the device global or hostpipe variable
/// represented in the LLVM IR by \c GV.
StringRef getGlobalVariableUniqueId(const GlobalVariable &GV) {
assert(GV.hasAttribute(SYCL_UNIQUE_ID_ATTR) &&
"a 'sycl-unique-id' string must be associated with every device "
"global variable");
"global or hostpipe variable");
return GV.getAttribute(SYCL_UNIQUE_ID_ATTR).getValueAsString();
}

Expand Down
80 changes: 80 additions & 0 deletions llvm/lib/SYCLLowerIR/HostPipes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//===------------- HostPipes.cpp - SYCL Host Pipes Pass -------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// See comments in the header.
//===----------------------------------------------------------------------===//

#include "llvm/SYCLLowerIR/HostPipes.h"
#include "llvm/SYCLLowerIR/CompileTimePropertiesPass.h"
#include "llvm/SYCLLowerIR/DeviceGlobals.h"

#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Module.h"

#include <cassert>

using namespace llvm;

namespace {

constexpr StringRef SYCL_HOST_PIPE_ATTR = "sycl-host-pipe";
constexpr StringRef SYCL_HOST_PIPE_SIZE_ATTR = "sycl-host-pipe-size";

/// Returns the size (in bytes) of the type \c T of the host
/// pipe variable.
///
/// The function gets this value from the LLVM IR attribute \c
/// sycl-host-pipe-size.
///
/// @param GV [in] Host Pipe variable.
///
/// @returns the size (int bytes) of the underlying type \c T of the
/// host pipe variable represented in the LLVM IR by @GV.
uint32_t getHostPipeTypeSize(const GlobalVariable &GV) {
assert(GV.hasAttribute(SYCL_HOST_PIPE_SIZE_ATTR) &&
"The host pipe variable must have the 'sycl-host-pipe-size' "
"attribute that must contain a number representing the size of the "
"underlying type T of the host pipe variable");
return getAttributeAsInteger<uint32_t>(GV, SYCL_HOST_PIPE_SIZE_ATTR);
}

} // anonymous namespace

namespace llvm {

/// Return \c true if the variable @GV is a host pipe variable.
///
/// The function checks whether the variable has the LLVM IR attribute \c
/// sycl-host-pipe.
/// @param GV [in] A variable to test.
///
/// @return \c true if the variable is a host pipe variable, \c false
/// otherwise.
bool isHostPipeVariable(const GlobalVariable &GV) {
return GV.hasAttribute(SYCL_HOST_PIPE_ATTR);
}

HostPipePropertyMapTy collectHostPipeProperties(const Module &M) {
HostPipePropertyMapTy HPM;
auto HostPipeNum = count_if(M.globals(), isHostPipeVariable);
if (HostPipeNum == 0)
return HPM;

HPM.reserve(HostPipeNum);

for (auto &GV : M.globals()) {
if (!isHostPipeVariable(GV))
continue;

HPM[getGlobalVariableUniqueId(GV)] = {getHostPipeTypeSize(GV)};
}

return HPM;
}

} // namespace llvm
1 change: 1 addition & 0 deletions llvm/lib/Support/PropertySetIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ constexpr char PropertySetRegistry::SYCL_ASSERT_USED[];
constexpr char PropertySetRegistry::SYCL_EXPORTED_SYMBOLS[];
constexpr char PropertySetRegistry::SYCL_DEVICE_GLOBALS[];
constexpr char PropertySetRegistry::SYCL_DEVICE_REQUIREMENTS[];
constexpr char PropertySetRegistry::SYCL_HOST_PIPES[];

} // namespace util
} // namespace llvm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $_ZN4sycl3_V13ext5intel12experimental9host_pipeI9D2HPipeIDiNS1_6oneapi12experime
@_ZN4sycl3_V13ext5intel12experimental9host_pipeI9D2HPipeIDiNS1_6oneapi12experimental10propertiesISt5tupleIJEEEEE6__pipeE = linkonce_odr dso_local addrspace(1) constant %struct.BasicKernel zeroinitializer, comdat, align 1 #0
; CHECK-IR: @_ZN4sycl3_V13ext5intel12experimental9host_pipeI9D2HPipeIDiNS1_6oneapi12experimental10propertiesISt5tupleIJEEEEE6__pipeE = linkonce_odr dso_local addrspace(1) constant %struct.BasicKernel zeroinitializer, comdat, align 1, !spirv.Decorations ![[#MN0:]]

attributes #0 = { "sycl-host-pipe" "sycl-unique-id"="_ZN4sycl3_V13ext5intel12experimental9host_pipeI9H2DPipeIDiNS1_6oneapi12experimental10propertiesISt5tupleIJEEEEE6__pipeE" }
attributes #0 = { "sycl-host-pipe" "sycl-host-pipe-size"="4" "sycl-unique-id"="_ZN4sycl3_V13ext5intel12experimental9host_pipeI9H2DPipeIDiNS1_6oneapi12experimental10propertiesISt5tupleIJEEEEE6__pipeE" }

; Ensure that the generated metadata nodes are correct
; CHECK-IR-DAG: ![[#MN0]] = !{![[#MN1:]]}
Expand Down
6 changes: 6 additions & 0 deletions llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "llvm/Passes/PassBuilder.h"
#include "llvm/SYCLLowerIR/DeviceGlobals.h"
#include "llvm/SYCLLowerIR/ESIMD/LowerESIMD.h"
#include "llvm/SYCLLowerIR/HostPipes.h"
#include "llvm/SYCLLowerIR/LowerInvokeSimd.h"
#include "llvm/SYCLLowerIR/LowerKernelProps.h"
#include "llvm/Support/CommandLine.h"
Expand Down Expand Up @@ -466,6 +467,11 @@ std::string saveModuleProperties(module_split::ModuleDesc &MD,
PropSet.add(PropSetRegTy::SYCL_DEVICE_GLOBALS, DevGlobalPropertyMap);
}

auto HostPipePropertyMap = collectHostPipeProperties(M);
if (!HostPipePropertyMap.empty()) {
PropSet.add(PropSetRegTy::SYCL_HOST_PIPES, HostPipePropertyMap);
}

std::error_code EC;
std::string SCFile = makeResultFileName(".prop", I, Suff);
raw_fd_ostream SCOut(SCFile, EC);
Expand Down
2 changes: 1 addition & 1 deletion opencl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(OCL_LOADER_REPO

# Repo tags/hashes

set(OCL_HEADERS_TAG dcd5bede6859d26833cd85f0d6bbcee7382dc9b3)
set(OCL_HEADERS_TAG 9ddb236e6eb3cf844f9e2f81677e1045f9bf838e)
set(OCL_LOADER_TAG 9a3e962f16f5097d2054233ad8b6dad51b6f41b7)

# OpenCL Headers
Expand Down
31 changes: 31 additions & 0 deletions sycl/include/sycl/detail/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class CG {
Memset2DUSM = 18,
CopyToDeviceGlobal = 19,
CopyFromDeviceGlobal = 20,
ReadWriteHostPipe = 21,
};

CG(CGTYPE Type, std::vector<std::vector<char>> ArgsStorage,
Expand Down Expand Up @@ -495,6 +496,36 @@ class CGMemset2DUSM : public CG {
char getValue() const { return MValue; }
};

/// "ReadWriteHostPipe" command group class.
class CGReadWriteHostPipe : public CG {
std::string PipeName;
bool Blocking;
void *HostPtr;
size_t TypeSize;
bool IsReadOp;

public:
CGReadWriteHostPipe(const std::string &Name, bool Block, void *Ptr,
size_t Size, bool Read,
std::vector<std::vector<char>> ArgsStorage,
std::vector<detail::AccessorImplPtr> AccStorage,
std::vector<std::shared_ptr<const void>> SharedPtrStorage,
std::vector<AccessorImplHost *> Requirements,
std::vector<detail::EventImplPtr> Events,
detail::code_location loc = {})
: CG(ReadWriteHostPipe, std::move(ArgsStorage), std::move(AccStorage),
std::move(SharedPtrStorage), std::move(Requirements),
std::move(Events), std::move(loc)),
PipeName(Name), Blocking(Block), HostPtr(Ptr), TypeSize(Size),
IsReadOp(Read) {}

std::string getPipeName() { return PipeName; }
void *getHostPtr() { return HostPtr; }
size_t getTypeSize() { return TypeSize; }
bool isBlocking() { return Blocking; }
bool isReadHostPipe() { return IsReadOp; }
};

/// "Copy to device_global" command group class.
class CGCopyToDeviceGlobal : public CG {
void *MSrc;
Expand Down
3 changes: 3 additions & 0 deletions sycl/include/sycl/detail/pi.def
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ _PI_API(piextUSMEnqueueMemcpy)
_PI_API(piextUSMEnqueuePrefetch)
_PI_API(piextUSMEnqueueMemAdvise)
_PI_API(piextUSMGetMemAllocInfo)
// Host pipes
_PI_API(piextEnqueueReadHostPipe)
_PI_API(piextEnqueueWriteHostPipe)

_PI_API(piextKernelSetArgMemObj)
_PI_API(piextKernelSetArgSampler)
Expand Down
Loading