From ac2e0a329f5d0e3967ea23c4c687135a0cdfa719 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Mon, 21 Nov 2022 11:27:33 -0800 Subject: [PATCH 01/56] [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 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. (cherry picked from commit 031f829) Zibai fixed all conflicts. --- llvm/include/llvm/Support/PropertySetIO.h | 1 + llvm/lib/Support/PropertySetIO.cpp | 1 + sycl/include/sycl/detail/pi.h | 2 + sycl/source/CMakeLists.txt | 1 + sycl/source/detail/device_binary_image.cpp | 1 + sycl/source/detail/device_binary_image.hpp | 2 + sycl/source/detail/host_pipe_map.cpp | 24 +++++++ sycl/source/detail/host_pipe_map_entry.hpp | 50 ++++++++++++++ .../program_manager/program_manager.cpp | 65 +++++++++++++++++++ .../program_manager/program_manager.hpp | 21 ++++++ sycl/test/abi/sycl_symbols_linux.dump | 1 + sycl/test/abi/sycl_symbols_windows.dump | 1 + 12 files changed, 170 insertions(+) create mode 100644 sycl/source/detail/host_pipe_map.cpp create mode 100644 sycl/source/detail/host_pipe_map_entry.hpp diff --git a/llvm/include/llvm/Support/PropertySetIO.h b/llvm/include/llvm/Support/PropertySetIO.h index 95dfa0190caf9..d878065809692 100644 --- a/llvm/include/llvm/Support/PropertySetIO.h +++ b/llvm/include/llvm/Support/PropertySetIO.h @@ -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). diff --git a/llvm/lib/Support/PropertySetIO.cpp b/llvm/lib/Support/PropertySetIO.cpp index 3639879214e0e..796769956401f 100644 --- a/llvm/lib/Support/PropertySetIO.cpp +++ b/llvm/lib/Support/PropertySetIO.cpp @@ -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 diff --git a/sycl/include/sycl/detail/pi.h b/sycl/include/sycl/detail/pi.h index 56b8b33fae583..3f262b96c1f7c 100644 --- a/sycl/include/sycl/detail/pi.h +++ b/sycl/include/sycl/detail/pi.h @@ -807,6 +807,8 @@ static const uint8_t PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL = 4; /// PropertySetRegistry::SYCL_DEVICE_REQUIREMENTS defined in PropertySetIO.h #define __SYCL_PI_PROPERTY_SET_SYCL_DEVICE_REQUIREMENTS \ "SYCL/device requirements" +/// PropertySetRegistry::SYCL_HOST_PIPES defined in PropertySetIO.h +#define __SYCL_PI_PROPERTY_SET_SYCL_HOST_PIPES "SYCL/host pipes" /// Program metadata tags recognized by the PI backends. For kernels the tag /// must appear after the kernel name. diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index 0a349fddc3ead..b5078e9e069f9 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -165,6 +165,7 @@ set(SYCL_SOURCES "detail/context_impl.cpp" "detail/device_binary_image.cpp" "detail/device_filter.cpp" + "detail/host_pipe_map.cpp" "detail/device_global_map.cpp" "detail/device_global_map_entry.cpp" "detail/device_impl.cpp" diff --git a/sycl/source/detail/device_binary_image.cpp b/sycl/source/detail/device_binary_image.cpp index 38aab48e0229e..210516675277c 100644 --- a/sycl/source/detail/device_binary_image.cpp +++ b/sycl/source/detail/device_binary_image.cpp @@ -176,6 +176,7 @@ void RTDeviceBinaryImage::init(pi_device_binary Bin) { ExportedSymbols.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_EXPORTED_SYMBOLS); DeviceGlobals.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_DEVICE_GLOBALS); DeviceRequirements.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_DEVICE_REQUIREMENTS); + HostPipes.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_HOST_PIPES); } DynRTDeviceBinaryImage::DynRTDeviceBinaryImage( diff --git a/sycl/source/detail/device_binary_image.hpp b/sycl/source/detail/device_binary_image.hpp index 6e92a288778ba..3cbd24e63642e 100644 --- a/sycl/source/detail/device_binary_image.hpp +++ b/sycl/source/detail/device_binary_image.hpp @@ -222,6 +222,7 @@ class RTDeviceBinaryImage { const PropertyRange &getDeviceRequirements() const { return DeviceRequirements; } + const PropertyRange &getHostPipes() const { return HostPipes; } std::uintptr_t getImageID() const { assert(Bin && "Image ID is not available without a binary image."); @@ -245,6 +246,7 @@ class RTDeviceBinaryImage { RTDeviceBinaryImage::PropertyRange ExportedSymbols; RTDeviceBinaryImage::PropertyRange DeviceGlobals; RTDeviceBinaryImage::PropertyRange DeviceRequirements; + RTDeviceBinaryImage::PropertyRange HostPipes; }; // Dynamically allocated device binary image, which de-allocates its binary diff --git a/sycl/source/detail/host_pipe_map.cpp b/sycl/source/detail/host_pipe_map.cpp new file mode 100644 index 0000000000000..3b0315e7f00b2 --- /dev/null +++ b/sycl/source/detail/host_pipe_map.cpp @@ -0,0 +1,24 @@ +//==-------------------- host_pipe_map.cpp -----------------------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { +namespace detail { +namespace host_pipe_map { + +__SYCL_EXPORT void add(const void *HostPipePtr, const char *UniqueId) { + detail::ProgramManager::getInstance().addOrInitHostPipeEntry(HostPipePtr, + UniqueId); +} + +} // namespace host_pipe_map +} // namespace detail +} // __SYCL_INLINE_VER_NAMESPACE(_V1) +} // namespace sycl diff --git a/sycl/source/detail/host_pipe_map_entry.hpp b/sycl/source/detail/host_pipe_map_entry.hpp new file mode 100644 index 0000000000000..464856bcc133d --- /dev/null +++ b/sycl/source/detail/host_pipe_map_entry.hpp @@ -0,0 +1,50 @@ +//==----------------- host_pipe_map_entry.hpp --------------------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include +#include + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { +namespace detail { + +struct HostPipeMapEntry { + std::string MUniqueId; + // Pointer to the host_pipe on host. + const void *MHostPipePtr; + // Size of the underlying type in the host_pipe. + std::uint32_t MHostPipeTSize; + + // Constructor only initializes with the pointer and ID. + // Other members will be initialized later + HostPipeMapEntry(std::string UniqueId, const void *HostPipePtr) + : MUniqueId(UniqueId), MHostPipePtr(HostPipePtr), MHostPipeTSize(0) {} + + // Constructor only initializes with the size and ID. + // Other members will be initialized later + HostPipeMapEntry(std::string UniqueId, std::uint32_t HostPipeTSize) + : MUniqueId(UniqueId), MHostPipePtr(nullptr), + MHostPipeTSize(HostPipeTSize) {} + + void initialize(std::uint32_t HostPipeTSize) { + assert(HostPipeTSize != 0 && "Host pipe initialized with 0 size."); + assert(MHostPipeTSize == 0 && "Host pipe has already been initialized."); + MHostPipeTSize = HostPipeTSize; + } + + void initialize(const void *HostPipePtr) { + assert(!MHostPipePtr && "Host pipe pointer has already been initialized."); + MHostPipePtr = HostPipePtr; + } +}; + +} // namespace detail +} // __SYCL_INLINE_VER_NAMESPACE(_V1) +} // namespace sycl diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index a197193d35432..714771f0bf971 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1312,6 +1312,39 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) { } } } + // ... and initialize associated host_pipe information + { + std::lock_guard HostPipesGuard(m_HostPipesMutex); + + auto HostPipes = Img->getHostPipes(); + for (const pi_device_binary_property &HostPipe : HostPipes) { + ByteArray HostPipeInfo = DeviceBinaryProperty(HostPipe).asByteArray(); + + // The supplied host_pipe info property is expected to contain: + // * 8 bytes - Size of the property. + // * 4 bytes - Size of the underlying type in the host_pipe. + // Note: Property may be padded. + constexpr unsigned int NumPropertySizeBytes = 8; + constexpr unsigned int NumTypeBytes = 4; + assert(HostPipeInfo.size() >= NumPropertySizeBytes + NumTypeBytes && + "Unexpected property size"); + auto TypeSize = *reinterpret_cast( + &HostPipeInfo[NumPropertySizeBytes]); + + auto ExistingHostPipe = m_HostPipes.find(HostPipe->Name); + if (ExistingHostPipe != m_HostPipes.end()) { + // If it has already been registered we update the information. + ExistingHostPipe->second->initialize(TypeSize); + } else { + // If it has not already been registered we create a new entry. + // Note: Pointer to the host pipe is not available here, so it + // cannot be set until registration happens. + auto EntryUPtr = + std::make_unique(HostPipe->Name, TypeSize); + m_HostPipes.emplace(HostPipe->Name, std::move(EntryUPtr)); + } + } + } m_DeviceImages[KSId].reset(new std::vector()); cacheKernelUsesAssertInfo(M, *Img); @@ -1631,6 +1664,38 @@ std::vector ProgramManager::getDeviceGlobalEntries( FoundEntries.push_back(DeviceGlobalEntry->second.get()); } return FoundEntries; + +void ProgramManager::addOrInitHostPipeEntry(const void *HostPipePtr, + const char *UniqueId) { + std::lock_guard HostPipesGuard(m_HostPipesMutex); + + assert(m_HostPipes.find(UniqueId) == m_HostPipes.end() && + "Host pipe has already been registered."); + auto ExistingHostPipe = m_HostPipes.find(UniqueId); + if (ExistingHostPipe != m_HostPipes.end()) { + ExistingHostPipe->second->initialize(HostPipePtr); + m_Ptr2HostPipe.insert({HostPipePtr, ExistingHostPipe->second.get()}); + return; + } + + auto EntryUPtr = std::make_unique(UniqueId, HostPipePtr); + auto NewEntry = m_HostPipes.emplace(UniqueId, std::move(EntryUPtr)); + m_Ptr2HostPipe.insert({HostPipePtr, NewEntry.first->second.get()}); +} + +HostPipeMapEntry * +ProgramManager::getHostPipeEntry(const std::string &UniqueId) { + std::lock_guard HostPipesGuard(m_HostPipesMutex); + auto Entry = m_HostPipes.find(UniqueId); + assert(Entry != m_HostPipes.end() && "Host pipe entry not found"); + return Entry->second.get(); +} + +HostPipeMapEntry *ProgramManager::getHostPipeEntry(const void *HostPipePtr) { + std::lock_guard HostPipesGuard(m_HostPipesMutex); + auto Entry = m_Ptr2HostPipe.find(HostPipePtr); + assert(Entry != m_Ptr2HostPipe.end() && "Host pipe entry not found"); + return Entry->second; } device_image_plain ProgramManager::getDeviceImageFromBinaryImage( diff --git a/sycl/source/detail/program_manager/program_manager.hpp b/sycl/source/detail/program_manager/program_manager.hpp index e85976eb621f4..8a8f185d8de89 100644 --- a/sycl/source/detail/program_manager/program_manager.hpp +++ b/sycl/source/detail/program_manager/program_manager.hpp @@ -9,10 +9,12 @@ #pragma once #include #include +#include #include #include #include #include +#include #include #include #include @@ -214,6 +216,17 @@ class ProgramManager { std::vector getDeviceGlobalEntries(const std::vector &UniqueIds, bool ExcludeDeviceImageScopeDecorated = false); + // The function inserts or initializes a host_pipe entry into the + // host_pipe map. + void addOrInitHostPipeEntry(const void *HostPipePtr, const char *UniqueId); + + // The function gets a host_pipe entry identified by the unique ID from + // the host_pipe map. + HostPipeMapEntry *getHostPipeEntry(const std::string &UniqueId); + + // The function gets a host_pipe entry identified by the pointer to the + // host_pipe object from the host_pipe map. + HostPipeMapEntry *getHostPipeEntry(const void *HostPipePtr); device_image_plain getDeviceImageFromBinaryImage(RTDeviceBinaryImage *BinImage, @@ -424,6 +437,14 @@ class ProgramManager { /// Protects m_DeviceGlobals and m_Ptr2DeviceGlobal. std::mutex m_DeviceGlobalsMutex; + + // Maps between host_pipe identifiers and associated information. + std::unordered_map> + m_HostPipes; + std::unordered_map m_Ptr2HostPipe; + + /// Protects m_HostPipes and m_Ptr2HostPipe. + std::mutex m_HostPipesMutex; }; } // namespace detail } // __SYCL_INLINE_VER_NAMESPACE(_V1) diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 21f2d70806e09..1cb963130a502 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3823,6 +3823,7 @@ _ZN4sycl3_V16detail13MemoryManager7releaseESt10shared_ptrINS1_12context_implEEPN _ZN4sycl3_V16detail13MemoryManager8allocateESt10shared_ptrINS1_12context_implEEPNS1_11SYCLMemObjIEbPvSt6vectorIS3_INS1_10event_implEESaISB_EERP9_pi_event _ZN4sycl3_V16detail13MemoryManager8copy_usmEPKvSt10shared_ptrINS1_10queue_implEEmPvSt6vectorIP9_pi_eventSaISB_EEPSB_ _ZN4sycl3_V16detail13MemoryManager8fill_usmEPvSt10shared_ptrINS1_10queue_implEEmiSt6vectorIP9_pi_eventSaIS9_EEPS9_ +_ZN4sycl3_V16detail13host_pipe_map3addEPKvPKc _ZN4sycl3_V16detail13make_platformEmNS0_7backendE _ZN4sycl3_V16detail13select_deviceERKSt8functionIFiRKNS0_6deviceEEE _ZN4sycl3_V16detail13select_deviceERKSt8functionIFiRKNS0_6deviceEEERKNS0_7contextE diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index edb7e962bd2bb..ece5c55ac03a3 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -750,6 +750,7 @@ ?accessGlobalFlushBuf@stream_impl@detail@_V1@sycl@@QEAA?AV?$accessor@D$00$0EAC@$0HNO@$0A@V?$accessor_property_list@$$V@oneapi@ext@_V1@sycl@@@34@AEAVhandler@34@@Z ?accessGlobalOffset@stream_impl@detail@_V1@sycl@@QEAA?AV?$accessor@I$00$0EAF@$0HNO@$0A@V?$accessor_property_list@$$V@oneapi@ext@_V1@sycl@@@34@AEAVhandler@34@@Z ?add@device_global_map@detail@_V1@sycl@@YAXPEBXPEBD@Z +?add@host_pipe_map@detail@_V1@sycl@@YAXPEBXPEBD@Z ?addHostAccessorAndWait@detail@_V1@sycl@@YAXPEAVAccessorImplHost@123@@Z ?addInteropObject@buffer_impl@detail@_V1@sycl@@QEBAXAEAV?$vector@_KV?$allocator@_K@std@@@std@@@Z ?addOrReplaceAccessorProperties@SYCLMemObjT@detail@_V1@sycl@@QEAAXAEBVproperty_list@34@@Z From 8e054e22752738648f059970f36bba47d4060020 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Thu, 24 Mar 2022 12:46:21 -0700 Subject: [PATCH 02/56] Add pi extension API for host pipes Setup lower runtime extension functions for host pipes. See also https://github.com/intel/llvm/pull/5766 https://github.com/intel/llvm/pull/5851 Host pipe sycl spec: https://github.com/intel/llvm/pull/5838 (cherry picked from commit e4d513c77369936d4cfe653d178981df6bce4c90) Zibai fixed the conflict. --- buildbot/dependency.py | 6 +- opencl/CMakeLists.txt | 4 +- sycl/include/sycl/detail/pi.def | 3 + sycl/include/sycl/detail/pi.h | 49 ++++++++++++++ sycl/plugins/cuda/pi_cuda.cpp | 39 +++++++++++ .../esimd_emulator/pi_esimd_emulator.cpp | 19 ++++++ sycl/plugins/hip/pi_hip.cpp | 40 ++++++++++++ sycl/plugins/level_zero/pi_level_zero.cpp | 64 +++++++++++++++++++ sycl/plugins/opencl/pi_opencl.cpp | 62 ++++++++++++++++++ sycl/test/abi/pi_level_zero_symbol_check.dump | 2 + sycl/test/abi/pi_opencl_symbol_check.dump | 2 + 11 files changed, 285 insertions(+), 5 deletions(-) diff --git a/buildbot/dependency.py b/buildbot/dependency.py index 8697dbfb0f991..e14388d49ef9e 100644 --- a/buildbot/dependency.py +++ b/buildbot/dependency.py @@ -49,8 +49,8 @@ def do_dependency(args): # fetch OpenCL headers ocl_header_dir = os.path.join(args.obj_dir, "OpenCL-Headers") if not os.path.isdir(ocl_header_dir): - clone_cmd = ["git", "clone", "https://github.com/KhronosGroup/OpenCL-Headers", - "OpenCL-Headers", "-b", "main"] + clone_cmd = ["git", "clone", "https://github.com/zibaiwan/OpenCL-Headers", + "OpenCL-Headers", "-b", "host-pipe"] # TODO: Remove change once upstream header changed subprocess.check_call(clone_cmd, cwd=args.obj_dir) else: fetch_cmd = ["git", "pull", "--ff", "--ff-only", "origin"] @@ -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", "35c1b8458b9118c68ddde2b0961509583ba4c1d8"] # TODO: Remove change once upstream header changed subprocess.check_call(checkout_cmd, cwd=ocl_header_dir) # fetch and build OpenCL ICD loader diff --git a/opencl/CMakeLists.txt b/opencl/CMakeLists.txt index 1442a1ac43075..32732ec9a09aa 100644 --- a/opencl/CMakeLists.txt +++ b/opencl/CMakeLists.txt @@ -14,13 +14,13 @@ endif() # Repo URLs set(OCL_HEADERS_REPO - "https://github.com/KhronosGroup/OpenCL-Headers.git") + "https://github.com/zibaiwan/OpenCL-Headers.git") #TODO: Change it back once the official header is in. set(OCL_LOADER_REPO "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") # Repo tags/hashes -set(OCL_HEADERS_TAG dcd5bede6859d26833cd85f0d6bbcee7382dc9b3) +set(OCL_HEADERS_TAG 35c1b8458b9118c68ddde2b0961509583ba4c1d8) #TODO: Change it back once the official header is in. set(OCL_LOADER_TAG 9a3e962f16f5097d2054233ad8b6dad51b6f41b7) # OpenCL Headers diff --git a/sycl/include/sycl/detail/pi.def b/sycl/include/sycl/detail/pi.def index eda09035c883e..2e71783720def 100644 --- a/sycl/include/sycl/detail/pi.def +++ b/sycl/include/sycl/detail/pi.def @@ -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) diff --git a/sycl/include/sycl/detail/pi.h b/sycl/include/sycl/detail/pi.h index 3f262b96c1f7c..50976bbc236d0 100644 --- a/sycl/include/sycl/detail/pi.h +++ b/sycl/include/sycl/detail/pi.h @@ -1927,6 +1927,55 @@ pi_result piextEnqueueDeviceGlobalVariableRead( /// /// Plugin /// +/// +// Host Pipes +/// + +/// Read from pipe of a given name +/// +/// @param queue a valid host command-queue in which the read / write command +/// will be queued. command_queue and program must be created with the same +/// OpenCL context. +/// @param program a program object with a successfully built executable. +/// @param pipe_symbol the name of the program scope pipe global variable. +/// @param blocking indicate if the read and write operations are blocking or +/// non-blocking +/// @param ptr a pointer to buffer in host memory that will hold resulting data +/// from pipe +/// @param size size of the memory region to read or write, in bytes. +/// @param num_events_in_waitlist number of events in the wait list. +/// @param events_waitlist specify events that need to complete before this +/// particular command can be executed. +/// @param event returns an event object that identifies this read / write +/// command and can be used to query or queue a wait for this command to +/// complete. +__SYCL_EXPORT pi_result piextEnqueueReadHostPipe( + pi_queue queue, pi_program program, const char *pipe_symbol, + pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, pi_event *event); + +/// Write to pipe of a given name +/// +/// @param queue a valid host command-queue in which the read / write command +/// will be queued. command_queue and program must be created with the same +/// OpenCL context. +/// @param program a program object with a successfully built executable. +/// @param pipe_symbol the name of the program scope pipe global variable. +/// @param blocking indicate if the read and write operations are blocking or +/// non-blocking +/// @param ptr a pointer to buffer in host memory that holds data to be written +/// to host pipe. +/// @param size size of the memory region to read or write, in bytes. +/// @param num_events_in_waitlist number of events in the wait list. +/// @param events_waitlist specify events that need to complete before this +/// particular command can be executed. +/// @param event returns an event object that identifies this read / write +/// command and can be used to query or queue a wait for this command to +/// complete. +__SYCL_EXPORT pi_result piextEnqueueWriteHostPipe( + pi_queue queue, pi_program program, const char *pipe_symbol, + pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, pi_event *event); /// API to get Plugin internal data, opaque to SYCL RT. Some devices whose /// device code is compiled by the host compiler (e.g. CPU emulators) may use it diff --git a/sycl/plugins/cuda/pi_cuda.cpp b/sycl/plugins/cuda/pi_cuda.cpp index 2d88978d87780..d8d1284744d70 100644 --- a/sycl/plugins/cuda/pi_cuda.cpp +++ b/sycl/plugins/cuda/pi_cuda.cpp @@ -5550,6 +5550,41 @@ pi_result cuda_piextEnqueueDeviceGlobalVariableRead( result = error; } return result; +/// Host Pipes +pi_result cuda_piextEnqueueReadHostPipe( + pi_queue queue, pi_program program, const char *pipe_symbol, + pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, pi_event *event) { + (void)queue; + (void)program; + (void)pipe_symbol; + (void)blocking; + (void)ptr; + (void)size; + (void)num_events_in_waitlist; + (void)events_waitlist; + (void)event; + + sycl::detail::pi::die("cuda_piextEnqueueReadHostPipe not implemented"); + return {}; +} + +pi_result cuda_piextEnqueueWriteHostPipe( + pi_queue queue, pi_program program, const char *pipe_symbol, + pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, pi_event *event) { + (void)queue; + (void)program; + (void)pipe_symbol; + (void)blocking; + (void)ptr; + (void)size; + (void)num_events_in_waitlist; + (void)events_waitlist; + (void)event; + + sycl::detail::pi::die("cuda_piextEnqueueWriteHostPipe not implemented"); + return {}; } // This API is called by Sycl RT to notify the end of the plugin lifetime. @@ -5738,6 +5773,10 @@ pi_result piPluginInit(pi_plugin *PluginInit) { _PI_CL(piextEnqueueDeviceGlobalVariableRead, cuda_piextEnqueueDeviceGlobalVariableRead) + // Host Pipe + _PI_CL(piextEnqueueReadHostPipe, cuda_piextEnqueueReadHostPipe) + _PI_CL(piextEnqueueWriteHostPipe, cuda_piextEnqueueWriteHostPipe) + _PI_CL(piextKernelSetArgMemObj, cuda_piextKernelSetArgMemObj) _PI_CL(piextKernelSetArgSampler, cuda_piextKernelSetArgSampler) _PI_CL(piPluginGetLastError, cuda_piPluginGetLastError) diff --git a/sycl/plugins/esimd_emulator/pi_esimd_emulator.cpp b/sycl/plugins/esimd_emulator/pi_esimd_emulator.cpp index 0fc2a5a10f4f9..ef1a0ea53913e 100644 --- a/sycl/plugins/esimd_emulator/pi_esimd_emulator.cpp +++ b/sycl/plugins/esimd_emulator/pi_esimd_emulator.cpp @@ -2002,6 +2002,25 @@ pi_result piextUSMGetMemAllocInfo(pi_context, const void *, pi_mem_alloc_info, DIE_NO_IMPLEMENTATION; } +/// Host Pipes +pi_result piextEnqueueReadHostPipe(pi_queue queue, pi_program program, + const char *pipe_symbol, pi_bool blocking, + void *ptr, size_t size, + pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, + pi_event *event) { + DIE_NO_IMPLEMENTATION; +} + +pi_result piextEnqueueWriteHostPipe(pi_queue queue, pi_program program, + const char *pipe_symbol, pi_bool blocking, + void *ptr, size_t size, + pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, + pi_event *event) { + DIE_NO_IMPLEMENTATION; +} + pi_result piKernelSetExecInfo(pi_kernel, pi_kernel_exec_info, size_t, const void *) { DIE_NO_IMPLEMENTATION; diff --git a/sycl/plugins/hip/pi_hip.cpp b/sycl/plugins/hip/pi_hip.cpp index ddca2a872adfc..0903838fe4148 100644 --- a/sycl/plugins/hip/pi_hip.cpp +++ b/sycl/plugins/hip/pi_hip.cpp @@ -5317,6 +5317,42 @@ pi_result hip_piextEnqueueDeviceGlobalVariableRead( sycl::detail::pi::die( "hip_piextEnqueueDeviceGlobalVariableRead not implemented"); +/// Host Pipes +pi_result hip_piextEnqueueReadHostPipe(pi_queue queue, pi_program program, + const char *pipe_symbol, + pi_bool blocking, void *ptr, size_t size, + pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, + pi_event *event) { + (void)queue; + (void)program; + (void)pipe_symbol; + (void)blocking; + (void)ptr; + (void)size; + (void)num_events_in_waitlist; + (void)events_waitlist; + (void)event; + + sycl::detail::pi::die("hip_piextEnqueueReadHostPipe not implemented"); + return {}; +} + +pi_result hip_piextEnqueueWriteHostPipe( + pi_queue queue, pi_program program, const char *pipe_symbol, + pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, pi_event *event) { + (void)queue; + (void)program; + (void)pipe_symbol; + (void)blocking; + (void)ptr; + (void)size; + (void)num_events_in_waitlist; + (void)events_waitlist; + (void)event; + + sycl::detail::pi::die("hip_piextEnqueueWriteHostPipe not implemented"); return {}; } @@ -5506,6 +5542,10 @@ pi_result piPluginInit(pi_plugin *PluginInit) { _PI_CL(piextEnqueueDeviceGlobalVariableRead, hip_piextEnqueueDeviceGlobalVariableRead) + // Host Pipe + _PI_CL(piextEnqueueReadHostPipe, hip_piextEnqueueReadHostPipe) + _PI_CL(piextEnqueueWriteHostPipe, hip_piextEnqueueWriteHostPipe) + _PI_CL(piextKernelSetArgMemObj, hip_piextKernelSetArgMemObj) _PI_CL(piextKernelSetArgSampler, hip_piextKernelSetArgSampler) _PI_CL(piPluginGetLastError, hip_piPluginGetLastError) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index cf4940d1d36b5..cde8bfb45b995 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -7933,6 +7933,70 @@ pi_result piextEnqueueDeviceGlobalVariableRead( PI_COMMAND_TYPE_DEVICE_GLOBAL_VARIABLE_READ, Queue, Dst, BlockingRead, Count, pi_cast(GlobalVarPtr) + Offset, NumEventsInWaitList, EventsWaitList, Event, PreferCopyEngine); +/// API for Read from host pipe. +/// +/// \param Queue is the queue +/// \param Program is the program containing the device variable +/// \param PipeSymbol is the unique identifier for the device variable +/// \param Blocking is true if the write should block +/// \param Ptr is a pointer to where the data will be copied to +/// \param Size is size of the data that is read/written from/to pipe +/// \param NumEventsInWaitList is a number of events in the wait list +/// \param EventWaitList is the wait list +/// \param Event is the resulting event +pi_result piextEnqueueReadHostPipe(pi_queue Queue, pi_program Program, + const char *PipeSymbol, pi_bool Blocking, + void *Ptr, size_t Size, + pi_uint32 NumEventsInWaitList, + const pi_event *EventsWaitList, + pi_event *Event) { + (void)Queue; + (void)Program; + (void)PipeSymbol; + (void)Blocking; + (void)Ptr; + (void)Size; + (void)NumEventsInWaitList; + (void)EventsWaitList; + (void)Event; + + PI_ASSERT(Queue, PI_ERROR_INVALID_QUEUE); + + die("piextEnqueueReadHostPipe: not implemented"); + return {}; +} + +/// API for write to pipe of a given name. +/// +/// \param Queue is the queue +/// \param Program is the program containing the device variable +/// \param PipeSymbol is the unique identifier for the device variable +/// \param Blocking is true if the write should block +/// \param Ptr is a pointer to where the data must be copied from +/// \param Size is size of the data that is read/written from/to pipe +/// \param NumEventsInWaitList is a number of events in the wait list +/// \param EventWaitList is the wait list +/// \param Event is the resulting event +pi_result piextEnqueueWriteHostPipe(pi_queue Queue, pi_program Program, + const char *PipeSymbol, pi_bool Blocking, + void *Ptr, size_t Size, + pi_uint32 NumEventsInWaitList, + const pi_event *EventsWaitList, + pi_event *Event) { + (void)Queue; + (void)Program; + (void)PipeSymbol; + (void)Blocking; + (void)Ptr; + (void)Size; + (void)NumEventsInWaitList; + (void)EventsWaitList; + (void)Event; + + PI_ASSERT(Queue, PI_ERROR_INVALID_QUEUE); + + die("piextEnqueueWriteHostPipe: not implemented"); + return {}; } pi_result piKernelSetExecInfo(pi_kernel Kernel, pi_kernel_exec_info ParamName, diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index 2c44f0cfe9eb3..1a123ff1e8364 100644 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -71,6 +71,9 @@ CONSTFIX char clEnqueueWriteGlobalVariableName[] = "clEnqueueWriteGlobalVariableINTEL"; CONSTFIX char clEnqueueReadGlobalVariableName[] = "clEnqueueReadGlobalVariableINTEL"; +// Names of host pipe functions queried from OpenCL +CONSTFIX char clEnqueueReadHostPipeName[] = "clEnqueueReadHostPipeIntelFPGA"; +CONSTFIX char clEnqueueWriteHostPipeName[] = "clEnqueueWriteHostPipeIntelFPGA"; #undef CONSTFIX @@ -1684,6 +1687,62 @@ pi_result piextEnqueueDeviceGlobalVariableRead( blocking_read, count, offset, dst, num_events_in_wait_list, cast(event_wait_list), cast(event)); return cast(Res); +pi_result piextEnqueueReadHostPipe(pi_queue queue, pi_program program, + const char *pipe_symbol, pi_bool blocking, + void *ptr, size_t size, + pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, + pi_event *event) { + cl_context CLContext; + cl_int CLErr = + clGetCommandQueueInfo(cast(queue), CL_QUEUE_CONTEXT, + sizeof(cl_context), &CLContext, nullptr); + if (CLErr != CL_SUCCESS) { + return cast(CLErr); + } + + clEnqueueReadHostPipeIntelFPGA_fn FuncPtr = nullptr; + pi_result RetVal = getExtFuncFromContext( + cast(CLContext), &FuncPtr); + + if (FuncPtr) { + RetVal = cast(FuncPtr( + cast(queue), cast(program), pipe_symbol, + blocking, ptr, size, num_events_in_waitlist, + cast(events_waitlist), cast(event))); + } + + return RetVal; +} + +pi_result piextEnqueueWriteHostPipe(pi_queue queue, pi_program program, + const char *pipe_symbol, pi_bool blocking, + void *ptr, size_t size, + pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, + pi_event *event) { + cl_context CLContext; + cl_int CLErr = + clGetCommandQueueInfo(cast(queue), CL_QUEUE_CONTEXT, + sizeof(cl_context), &CLContext, nullptr); + if (CLErr != CL_SUCCESS) { + return cast(CLErr); + } + + clEnqueueWriteHostPipeIntelFPGA_fn FuncPtr = nullptr; + pi_result RetVal = getExtFuncFromContext( + cast(CLContext), &FuncPtr); + + if (FuncPtr) { + RetVal = cast(FuncPtr( + cast(queue), cast(program), pipe_symbol, + blocking, ptr, size, num_events_in_waitlist, + cast(events_waitlist), cast(event))); + } + + return RetVal; } /// API to set attributes controlling kernel execution @@ -1972,6 +2031,9 @@ pi_result piPluginInit(pi_plugin *PluginInit) { piextEnqueueDeviceGlobalVariableWrite) _PI_CL(piextEnqueueDeviceGlobalVariableRead, piextEnqueueDeviceGlobalVariableRead) + // Host Pipe + _PI_CL(piextEnqueueReadHostPipe, piextEnqueueReadHostPipe) + _PI_CL(piextEnqueueWriteHostPipe, piextEnqueueWriteHostPipe) _PI_CL(piextKernelSetArgMemObj, piextKernelSetArgMemObj) _PI_CL(piextKernelSetArgSampler, piextKernelSetArgSampler) diff --git a/sycl/test/abi/pi_level_zero_symbol_check.dump b/sycl/test/abi/pi_level_zero_symbol_check.dump index fbefe601f3675..4363024cda8a5 100644 --- a/sycl/test/abi/pi_level_zero_symbol_check.dump +++ b/sycl/test/abi/pi_level_zero_symbol_check.dump @@ -89,6 +89,8 @@ piextContextSetExtendedDeleter piextDeviceCreateWithNativeHandle piextDeviceGetNativeHandle piextDeviceSelectBinary +piextEnqueueReadHostPipe +piextEnqueueWriteHostPipe piextEventCreateWithNativeHandle piextEventGetNativeHandle piextGetDeviceFunctionPointer diff --git a/sycl/test/abi/pi_opencl_symbol_check.dump b/sycl/test/abi/pi_opencl_symbol_check.dump index 7925dfcbc6b53..9707c21163b95 100644 --- a/sycl/test/abi/pi_opencl_symbol_check.dump +++ b/sycl/test/abi/pi_opencl_symbol_check.dump @@ -38,6 +38,8 @@ piextContextGetNativeHandle piextDeviceCreateWithNativeHandle piextDeviceGetNativeHandle piextDeviceSelectBinary +piextEnqueueReadHostPipe +piextEnqueueWriteHostPipe piextEventCreateWithNativeHandle piextGetDeviceFunctionPointer piextKernelCreateWithNativeHandle From 0fc38795aaaad41756bfd64f11a04743a887b531 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 23 Nov 2022 08:49:47 -0800 Subject: [PATCH 03/56] [SYCL] Add new hostpipe API to PIMockPlugin --- sycl/unittests/helpers/PiMockPlugin.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sycl/unittests/helpers/PiMockPlugin.hpp b/sycl/unittests/helpers/PiMockPlugin.hpp index c2ac5e6863b8b..05d3d8b70877d 100644 --- a/sycl/unittests/helpers/PiMockPlugin.hpp +++ b/sycl/unittests/helpers/PiMockPlugin.hpp @@ -1138,3 +1138,24 @@ inline pi_result mock_piGetDeviceAndHostTimer(pi_device device, } return PI_SUCCESS; } +/// +// Host Pipes +/// + +inline pi_result mock_piextEnqueueReadHostPipe( + pi_queue queue, pi_program program, const char *pipe_symbol, + pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, pi_event *event) { + *event = createDummyHandle(); + return PI_SUCCESS; +} + +inline pi_result mock_piextEnqueueWriteHostPipe( + pi_queue queue, pi_program program, const char *pipe_symbol, + pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist, + const pi_event *events_waitlist, pi_event *event) { + *event = createDummyHandle(); + return PI_SUCCESS; +} + + From 44342a65b7db46e89f9160458e0bb1046634badd Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Wed, 23 Nov 2022 12:38:46 -0800 Subject: [PATCH 04/56] [SYCL] Add data_flow_pipe properties Defines new properties for data flow pipes (cherry picked from commit a8bc6ea) Zibai fixed the conflict --- .../intel/experimental/pipe_properties.hpp | 197 ++++++++++++++++++ .../sycl/ext/oneapi/properties/property.hpp | 9 +- sycl/include/sycl/sycl.hpp | 1 + .../extensions/properties/properties_pipe.cpp | 168 +++++++++++++++ 4 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp create mode 100644 sycl/test/extensions/properties/properties_pipe.cpp diff --git a/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp new file mode 100644 index 0000000000000..5932abfa30ef3 --- /dev/null +++ b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp @@ -0,0 +1,197 @@ +//==----- pipe_properties.hpp - SYCL properties associated with data flow pipe +//---==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include +#include + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { +namespace ext { +namespace intel { +namespace experimental { + +struct min_capacity_key { + template + using value_t = oneapi::experimental::property_value< + min_capacity_key, std::integral_constant>; +}; + +struct ready_latency_key { + template + using value_t = oneapi::experimental::property_value< + ready_latency_key, std::integral_constant>; +}; + +struct bits_per_symbol_key { + template + using value_t = + oneapi::experimental::property_value>; +}; + +struct uses_valid_key { + template + using value_t = + oneapi::experimental::property_value>; +}; + +struct uses_ready_key { + template + using value_t = + oneapi::experimental::property_value>; +}; + +struct in_csr_key { + template + using value_t = + oneapi::experimental::property_value>; +}; + +struct first_symbol_in_high_order_bits_key { + template + using value_t = oneapi::experimental::property_value< + first_symbol_in_high_order_bits_key, + sycl::detail::bool_constant>; +}; + +enum class protocol_name : std::uint16_t { AVALON, AXI }; +struct protocol_key { + template + using value_t = oneapi::experimental::property_value< + protocol_key, std::integral_constant>; +}; + +template +inline constexpr min_capacity_key::value_t min_capacity; + +template +inline constexpr ready_latency_key::value_t ready_latency; + +template +inline constexpr bits_per_symbol_key::value_t bits_per_symbol; + +template +inline constexpr uses_valid_key::value_t uses_valid; +inline constexpr uses_valid_key::value_t uses_valid_on; +inline constexpr uses_valid_key::value_t uses_valid_off; + +template +inline constexpr uses_ready_key::value_t uses_ready; +inline constexpr uses_ready_key::value_t uses_ready_on; +inline constexpr uses_ready_key::value_t uses_ready_off; + +template inline constexpr in_csr_key::value_t in_csr; +inline constexpr in_csr_key::value_t in_csr_on; +inline constexpr in_csr_key::value_t in_csr_off; + +template +inline constexpr first_symbol_in_high_order_bits_key::value_t + first_symbol_in_high_order_bits; +inline constexpr first_symbol_in_high_order_bits_key::value_t + first_symbol_in_high_order_bits_on; +inline constexpr first_symbol_in_high_order_bits_key::value_t + first_symbol_in_high_order_bits_off; + +template +inline constexpr protocol_key::value_t protocol; +inline constexpr protocol_key::value_t protocol_avalon; +inline constexpr protocol_key::value_t protocol_axi; + +} // namespace experimental +} // namespace intel + +namespace oneapi { +namespace experimental { + +template <> +struct is_property_key : std::true_type { +}; +template <> +struct is_property_key + : std::true_type {}; +template <> +struct is_property_key + : std::true_type {}; +template <> +struct is_property_key : std::true_type {}; +template <> +struct is_property_key : std::true_type {}; +template <> +struct is_property_key : std::true_type {}; +template <> +struct is_property_key + : std::true_type {}; +template <> +struct is_property_key : std::true_type {}; + +namespace detail { +template <> struct PropertyToKind { + static constexpr PropKind Kind = PropKind::MinCapacity; +}; +template <> struct PropertyToKind { + static constexpr PropKind Kind = PropKind::ReadyLatency; +}; +template <> struct PropertyToKind { + static constexpr PropKind Kind = PropKind::BitsPerSymbol; +}; +template <> struct PropertyToKind { + static constexpr PropKind Kind = PropKind::UsesValid; +}; +template <> struct PropertyToKind { + static constexpr PropKind Kind = PropKind::UsesReady; +}; +template <> struct PropertyToKind { + static constexpr PropKind Kind = PropKind::ImplementInCSR; +}; +template <> +struct PropertyToKind< + intel::experimental::first_symbol_in_high_order_bits_key> { + static constexpr PropKind Kind = PropKind::FirstSymbolInHigherOrderBit; +}; +template <> struct PropertyToKind { + static constexpr PropKind Kind = PropKind::PipeProtocol; +}; + +template <> +struct IsCompileTimeProperty + : std::true_type {}; +template <> +struct IsCompileTimeProperty + : std::true_type {}; +template <> +struct IsCompileTimeProperty + : std::true_type {}; +template <> +struct IsCompileTimeProperty + : std::true_type {}; +template <> +struct IsCompileTimeProperty + : std::true_type {}; +template <> +struct IsCompileTimeProperty : std::true_type { +}; +template <> +struct IsCompileTimeProperty< + intel::experimental::first_symbol_in_high_order_bits_key> : std::true_type { +}; +template <> +struct IsCompileTimeProperty + : std::true_type {}; + +} // namespace detail +} // namespace experimental +} // namespace intel +} // namespace ext +} // __SYCL_INLINE_VER_NAMESPACE(_V1) +} // namespace sycl diff --git a/sycl/include/sycl/ext/oneapi/properties/property.hpp b/sycl/include/sycl/ext/oneapi/properties/property.hpp index bcc911017e40e..5003c57c6162e 100644 --- a/sycl/include/sycl/ext/oneapi/properties/property.hpp +++ b/sycl/include/sycl/ext/oneapi/properties/property.hpp @@ -187,8 +187,15 @@ enum PropKind : uint32_t { MaxBurst = 21, WaitRequest = 22, Alignment = 23, + BitsPerSymbol = 24, + FirstSymbolInHigherOrderBit = 25, + MinCapacity = 26, + PipeProtocol = 27, + ReadyLatency = 28, + UsesReady = 29, + UsesValid = 30, // PropKindSize must always be the last value. - PropKindSize = 24, + PropKindSize = 31, }; // This trait must be specialized for all properties and must have a unique diff --git a/sycl/include/sycl/sycl.hpp b/sycl/include/sycl/sycl.hpp index c918714904a37..f71e487dffdf1 100644 --- a/sycl/include/sycl/sycl.hpp +++ b/sycl/include/sycl/sycl.hpp @@ -82,3 +82,4 @@ #include #include #include +#include diff --git a/sycl/test/extensions/properties/properties_pipe.cpp b/sycl/test/extensions/properties/properties_pipe.cpp new file mode 100644 index 0000000000000..2b4799ca9ba1e --- /dev/null +++ b/sycl/test/extensions/properties/properties_pipe.cpp @@ -0,0 +1,168 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s +// expected-no-diagnostics + +#include + +#include + +using namespace sycl::ext; + +constexpr sycl::ext::intel::experimental::protocol_name TestProtocol = + sycl::ext::intel::experimental::protocol_name::AVALON; + +int main() { + // Check that is_property_key is correctly specialized. + static_assert(sycl::ext::oneapi::experimental::is_property_key< + sycl::ext::intel::experimental::min_capacity_key>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_key< + sycl::ext::intel::experimental::ready_latency_key>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_key< + sycl::ext::intel::experimental::bits_per_symbol_key>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_key< + sycl::ext::intel::experimental::uses_valid_key>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_key< + sycl::ext::intel::experimental::uses_ready_key>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_key< + sycl::ext::intel::experimental::in_csr_key>::value); + static_assert( + sycl::ext::oneapi::experimental::is_property_key< + sycl::ext::intel::experimental::first_symbol_in_high_order_bits_key>:: + value); + static_assert(sycl::ext::oneapi::experimental::is_property_key< + sycl::ext::intel::experimental::protocol_key>::value); + + // Check that is_property_value is correctly specialized. + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::min_capacity<3>)>::value); + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::ready_latency<3>)>::value); + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::bits_per_symbol<3>)>::value); + + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::uses_valid)>::value); + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::uses_valid_on)>::value); + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::uses_valid_off)>::value); + + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::uses_ready)>::value); + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::uses_ready_on)>::value); + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::uses_ready_off)>::value); + + static_assert(sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::in_csr)>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::in_csr_on)>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::in_csr_off)>::value); + + static_assert(sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental:: + first_symbol_in_high_order_bits)>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental:: + first_symbol_in_high_order_bits_on)>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental:: + first_symbol_in_high_order_bits_off)>::value); + + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::protocol)>:: + value); + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::protocol_avalon)>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::protocol_axi)>::value); + + // Checks that fully specialized properties are the same as the templated + // variants. + static_assert(std::is_same_v< + decltype(sycl::ext::intel::experimental::uses_valid_on), + decltype(sycl::ext::intel::experimental::uses_valid)>); + static_assert(std::is_same_v< + decltype(sycl::ext::intel::experimental::uses_ready_off), + decltype(sycl::ext::intel::experimental::uses_ready)>); + static_assert( + std::is_same_v)>); + static_assert( + std::is_same_v)>); + static_assert( + std::is_same_v< + decltype(sycl::ext::intel::experimental::protocol_avalon), + decltype(sycl::ext::intel::experimental::protocol)>); + static_assert(std::is_same_v< + decltype(sycl::ext::intel::experimental::protocol_axi), + decltype(sycl::ext::intel::experimental::protocol< + sycl::ext::intel::experimental::protocol_name::AXI>)>); + + // Check that property lists will accept the new properties. + using P = decltype(sycl::ext::oneapi::experimental::properties( + sycl::ext::intel::experimental::min_capacity<0>, + sycl::ext::intel::experimental::ready_latency<1>, + sycl::ext::intel::experimental::bits_per_symbol<2>, + sycl::ext::intel::experimental::uses_valid, + sycl::ext::intel::experimental::uses_ready, + sycl::ext::intel::experimental::in_csr, + sycl::ext::intel::experimental::first_symbol_in_high_order_bits_off, + sycl::ext::intel::experimental::protocol_avalon)); + static_assert(sycl::ext::oneapi::experimental::is_property_list_v

); + static_assert( + P::has_property()); + static_assert( + P::has_property()); + static_assert( + P::has_property()); + static_assert( + P::has_property()); + static_assert( + P::has_property()); + static_assert(P::has_property()); + static_assert(P::has_property()); + static_assert( + P::has_property()); + + static_assert( + P::get_property() == + sycl::ext::intel::experimental::min_capacity<0>); + static_assert( + P::get_property() == + sycl::ext::intel::experimental::ready_latency<1>); + static_assert( + P::get_property() == + sycl::ext::intel::experimental::bits_per_symbol<2>); + static_assert( + P::get_property() == + sycl::ext::intel::experimental::uses_valid); + static_assert( + P::get_property() == + sycl::ext::intel::experimental::uses_ready); + static_assert(P::get_property() == + sycl::ext::intel::experimental::in_csr); + static_assert( + P::get_property() == + sycl::ext::intel::experimental::first_symbol_in_high_order_bits_off); + static_assert( + P::get_property() == + sycl::ext::intel::experimental::protocol_avalon); +} From 4e816d81fb842e1a83c2e3dd41887f37512baf03 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Fri, 25 Mar 2022 13:18:44 -0700 Subject: [PATCH 05/56] Register new command group to execute host pipe read/write operation Defines the flow of enqueue new host pipe operations (read/write), User provide the queue to enqueue this event, and the runtime queries the pipe address from registration using the given address and unique ID. The runtime pass the pipe name, and host address into queue submit of new command group. The enqueued command calls new opencl function, and provide the current program, queue, event wait list, pipe name, host pointer of the data destination. Spec: https://github.com/intel/llvm/pull/5838 (cherry picked from commit 12e9e85f2c77c33216e6e9653e1f9af37c4ab60b) Zibai fixed all the conflicts. --- sycl/include/sycl/detail/cg.hpp | 29 +++++++ .../ext/intel/experimental/host_pipes.hpp | 87 +++++++++++++++++++ .../intel/experimental/pipe_properties.hpp | 2 +- sycl/include/sycl/handler.hpp | 18 ++++ sycl/source/CMakeLists.txt | 1 + sycl/source/detail/host_pipe.cpp | 69 +++++++++++++++ sycl/source/detail/scheduler/commands.cpp | 53 +++++++++++ sycl/source/detail/scheduler/commands.hpp | 6 ++ sycl/source/handler.cpp | 18 ++++ sycl/test/abi/sycl_symbols_linux.dump | 1 + sycl/test/abi/symbol_size_alignment.cpp | 4 +- sycl/unittests/helpers/PiMockPlugin.hpp | 2 - 12 files changed, 285 insertions(+), 5 deletions(-) create mode 100644 sycl/include/sycl/ext/intel/experimental/host_pipes.hpp create mode 100644 sycl/source/detail/host_pipe.cpp diff --git a/sycl/include/sycl/detail/cg.hpp b/sycl/include/sycl/detail/cg.hpp index 17bc41ed15f46..cba29f866d40a 100644 --- a/sycl/include/sycl/detail/cg.hpp +++ b/sycl/include/sycl/detail/cg.hpp @@ -74,6 +74,7 @@ class CG { Memset2DUSM = 18, CopyToDeviceGlobal = 19, CopyFromDeviceGlobal = 20, + ReadWriteHostPipe = 21, }; CG(CGTYPE Type, std::vector> ArgsStorage, @@ -490,6 +491,34 @@ class CGMemset2DUSM : public CG { size_t getWidth() const { return MWidth; } size_t getHeight() const { return MHeight; } 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> ArgsStorage, + std::vector AccStorage, + std::vector> SharedPtrStorage, + std::vector Requirements, + std::vector 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. diff --git a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp new file mode 100644 index 0000000000000..00c80f1007d22 --- /dev/null +++ b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp @@ -0,0 +1,87 @@ +//==---------------- pipes.hpp - SYCL pipes ------------*- C++ -*-----------==// +// +// 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 +// +// ===--------------------------------------------------------------------=== // + +#pragma once + +#include +#include +#include +#include +#include +#include + +#ifdef XPTI_ENABLE_INSTRUMENTATION +#include +#include +#endif + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { +namespace ext { +namespace intel { +namespace experimental { + +template +class host_pipe { + static_assert( + sycl::ext::oneapi::experimental::is_property_list_v<_propertiesT>, + "Host pipe is available only through new property list"); +}; + +using default_pipe_properties = + decltype(sycl::ext::oneapi::experimental::properties(min_capacity<0>)); + +template +class +#ifdef __SYCL_DEVICE_ONLY__ + [[__sycl_detail__::add_ir_attributes_global_variable("sycl-host-access", + "readwrite")]] +#endif + // TODO: change name to pipe, and merge into the existing pipe + // implementation + host_pipe<_name, _dataT, _propertiesT, + std::enable_if_t>> { + static_assert( + sycl::ext::oneapi::experimental::is_property_list_v<_propertiesT>, + "Host pipe is available only through new property list"); + +public: + using value_type = _dataT; + static constexpr int32_t min_cap = + _propertiesT::template has_property() + ? _propertiesT::template get_property().value + : 0; + + // Blocking pipes + static _dataT read(queue & q, memory_order order = memory_order::seq_cst); + static void write(queue & q, const _dataT &data, + memory_order order = memory_order::seq_cst); + // Non-blocking pipes + static _dataT read(queue & q, bool &success_code, + memory_order order = memory_order::seq_cst); + static void write(queue & q, const _dataT &data, bool &success_code, + memory_order order = memory_order::seq_cst); + +private: + static constexpr int32_t m_Size = sizeof(_dataT); + static constexpr int32_t m_Alignment = alignof(_dataT); + +#ifdef __SYCL_DEVICE_ONLY__ + static constexpr struct ConstantPipeStorage m_Storage = {m_Size, m_Alignment, + min_capacity}; +#endif // __SYCL_DEVICE_ONLY__ +}; + +} // namespace experimental +} // namespace intel +} // namespace ext +} // __SYCL_INLINE_VER_NAMESPACE(_V1) +} // namespace sycl \ No newline at end of file diff --git a/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp index 5932abfa30ef3..215a1d7ee8e53 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp @@ -191,7 +191,7 @@ struct IsCompileTimeProperty } // namespace detail } // namespace experimental -} // namespace intel +} // namespace oneapi } // namespace ext } // __SYCL_INLINE_VER_NAMESPACE(_V1) } // namespace sycl diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index de460abac0d58..8ec443448a76c 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -2646,6 +2646,14 @@ class __SYCL_EXPORT handler { else commonUSMFill2DFallbackKernel(Dest, DestPitch, Pattern, Width, Height); } + /// Read from or write to host pipes given a host address and + /// \param Name name of the host pipe to be passed into lower level runtime + /// \param Ptr host pointer of host pipe as identified by address of its const + /// expr __pipe member \param Size the size of data getting read back / to. + /// /// \param Size the size of data getting read back / to. \param Blocking + /// if read/write opeartion is blocking \param Read 1 for read, 0 for write + void read_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, + bool Block, bool Read); /// Copies data from a USM memory region to a device_global. /// Throws an exception if the copy operation intends to write outside the @@ -2781,6 +2789,16 @@ class __SYCL_EXPORT handler { /// The list of valid SYCL events that need to complete /// before barrier command can be executed std::vector MEventsWaitWithBarrier; + /// Pipe name that uniquely identifies a pipe. + std::string HostPipeName; + /// Pipe host pointer, the address of its constexpr __pipe member. + void *HostPipePtr = nullptr; + /// Host pipe read write operation is blocking. + bool HostPipeBlocking = false; + /// The size of returned type for each read. + size_t HostPipeTypeSize = 0; + /// If the pipe operation is read or write, 1 for read 0 for write. + bool HostPipeRead = true; bool MIsHost = false; diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index b5078e9e069f9..f31aa09c7328f 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -177,6 +177,7 @@ set(SYCL_SOURCES "detail/global_handler.cpp" "detail/helpers.cpp" "detail/handler_proxy.cpp" + "detail/host_pipe.cpp" "detail/image_accessor_util.cpp" "detail/image_impl.cpp" "detail/jit_compiler.cpp" diff --git a/sycl/source/detail/host_pipe.cpp b/sycl/source/detail/host_pipe.cpp new file mode 100644 index 0000000000000..bc9fe33c555c7 --- /dev/null +++ b/sycl/source/detail/host_pipe.cpp @@ -0,0 +1,69 @@ +//==-------------------- host_pipe.cpp -----------------------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { +namespace ext { +namespace intel { +namespace experimental { + +template +_dataT +host_pipe<_name, _dataT, _propertiesT, + std::enable_if_t>>::read(queue &q, memory_order order) { + const device Dev = q.get_device(); + bool IsReadPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsReadPipeSupported) { + return &_dataT(); + } + // TODO: get pipe name from the pipe registration + _dataT data; + const std::string pipe_name = "pipename"; + size_t size = 4; + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, (void *)(&data), (size_t)size, false, + true /* read */); + }); + e.wait(); + return data; +} + +template +void host_pipe< + _name, _dataT, _propertiesT, + std::enable_if_t>>::write(queue &q, const _dataT &data, + memory_order order) { + const device Dev = q.get_device(); + bool IsReadPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsReadPipeSupported) { + return; + } + // TODO: get pipe name from the pipe registration + const std::string pipe_name = "pipename"; + const void *data_ptr = &data; + size_t size = 4; + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, (size_t)size, false, + false /* write */); + }); + e.wait(); +} + +// TODO: implement non blocking version + +} // namespace experimental +} // namespace intel +} // namespace ext +} // __SYCL_INLINE_VER_NAMESPACE(_V1) +} // namespace sycl \ No newline at end of file diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 0a8f02913c9c2..f238905868c5f 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -2330,6 +2330,43 @@ pi_int32 enqueueImpKernel( return PI_SUCCESS; } +pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, + const std::string &PipeName, bool blocking, + void *ptr, size_t size, + std::vector &RawEvents, + RT::PiEvent *OutEvent, bool read) { + // TODO: Few options of getting the kernel name / program object: + // 1. Encode this in the pipe registration + // 2. Initialize the pipe registration from first kernel launch, but then this + // will violate the spec + detail::OSModuleHandle M = + detail::OSUtil::getOSModuleHandle("HostPipeReadWriteKernelName"); + RT::PiProgram Program = + sycl::detail::ProgramManager::getInstance().getBuiltPIProgram( + M, Queue->getContextImplPtr(), Queue->getDeviceImplPtr(), + "HostPipeReadWriteKernelName"); + + // Get plugin for calling opencl functions + const detail::plugin &Plugin = Queue->getPlugin(); + + pi_queue pi_q = Queue->getHandleRef(); + pi_result Error; + if (read) { + Error = + Plugin.call_nocheck( + pi_q, Program, PipeName.c_str(), blocking, ptr, size, + RawEvents.size(), RawEvents.empty() ? nullptr : &RawEvents[0], + OutEvent); + } else { + Error = + Plugin.call_nocheck( + pi_q, Program, PipeName.c_str(), blocking, ptr, size, + RawEvents.size(), RawEvents.empty() ? nullptr : &RawEvents[0], + OutEvent); + } + return Error; +} + pi_int32 ExecCGCommand::enqueueImp() { if (getCG().getType() != CG::CGTYPE::CodeplayHostTask) waitForPreparedHostEvents(); @@ -2738,6 +2775,22 @@ pi_int32 ExecCGCommand::enqueueImp() { return CL_SUCCESS; } + case CG::CGTYPE::ReadWriteHostPipe: { + CGReadWriteHostPipe *ExecReadWriteHostPipe = + (CGReadWriteHostPipe *)MCommandGroup.get(); + std::string pipeName = ExecReadWriteHostPipe->getPipeName(); + void *hostPtr = ExecReadWriteHostPipe->getHostPtr(); + size_t typeSize = ExecReadWriteHostPipe->getTypeSize(); + bool blocking = ExecReadWriteHostPipe->isBlocking(); + bool read = ExecReadWriteHostPipe->isReadHostPipe(); + + if (!Event) { + Event = &MEvent->getHandleRef(); + } + + return enqueueReadWriteHostPipe(MQueue, pipeName, blocking, hostPtr, + typeSize, RawEvents, Event, read); + } case CG::CGTYPE::None: throw runtime_error("CG type not implemented.", PI_ERROR_INVALID_OPERATION); } diff --git a/sycl/source/detail/scheduler/commands.hpp b/sycl/source/detail/scheduler/commands.hpp index d4219770abbae..c204c45c5dfdc 100644 --- a/sycl/source/detail/scheduler/commands.hpp +++ b/sycl/source/detail/scheduler/commands.hpp @@ -585,6 +585,12 @@ class MemCpyCommandHost : public Command { void **MDstPtr = nullptr; }; +pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, + const std::string &PipeName, bool blocking, + void *ptr, size_t size, + std::vector &RawEvents, + RT::PiEvent *OutEvent, bool read); + pi_int32 enqueueImpKernel( const QueueImplPtr &Queue, NDRDescT &NDRDesc, std::vector &Args, const std::shared_ptr &KernelBundleImplPtr, diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 7fbb962df6b5a..e3ce029cbda8d 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -357,6 +357,14 @@ event handler::finalize() { std::move(MEvents), MOSModuleHandle, MCodeLoc)); break; } + case detail::CG::ReadWriteHostPipe: { + CommandGroup.reset(new detail::CGReadWriteHostPipe( + HostPipeName, HostPipeBlocking, HostPipePtr, HostPipeTypeSize, + HostPipeRead, std::move(MArgsStorage), std::move(MAccStorage), + std::move(MSharedPtrStorage), std::move(MRequirements), + std::move(MEvents), MCodeLoc)); + break; + } case detail::CG::None: if (detail::pi::trace(detail::pi::TraceLevel::PI_TRACE_ALL)) { std::cout << "WARNING: An empty command group is submitted." << std::endl; @@ -851,6 +859,16 @@ id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) { id<2> ItemLimit = Dev.get_info>() * Dev.get_info(); return id<2>{std::min(ItemLimit[0], Height), std::min(ItemLimit[1], Width)}; + +void handler::read_write_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block, bool Read) { + throwIfActionIsCreated(); + HostPipeName = Name; + HostPipePtr = Ptr; + HostPipeTypeSize = Size; + HostPipeBlocking = Block; + HostPipeRead = Read; + setType(detail::CG::ReadWriteHostPipe); } void handler::memcpyToDeviceGlobal(const void *DeviceGlobalPtr, const void *Src, diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 1cb963130a502..aa13d320558df 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3965,6 +3965,7 @@ _ZN4sycl3_V17handler19supportsUSMMemset2DEv _ZN4sycl3_V17handler20DisableRangeRoundingEv _ZN4sycl3_V17handler20associateWithHandlerEPNS0_6detail16AccessorBaseHostENS0_6access6targetE _ZN4sycl3_V17handler20memcpyToDeviceGlobalEPKvS3_bmm +_ZN4sycl3_V17handler20read_write_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmbb _ZN4sycl3_V17handler20setStateSpecConstSetEv _ZN4sycl3_V17handler22ext_oneapi_fill2d_implEPvmPKvmmm _ZN4sycl3_V17handler22memcpyFromDeviceGlobalEPvPKvbmm diff --git a/sycl/test/abi/symbol_size_alignment.cpp b/sycl/test/abi/symbol_size_alignment.cpp index 2372c13d65e06..8329cd53ab16b 100644 --- a/sycl/test/abi/symbol_size_alignment.cpp +++ b/sycl/test/abi/symbol_size_alignment.cpp @@ -52,9 +52,9 @@ int main() { check(); check(); #ifdef _MSC_VER - check(); + check(); // TODO double check whether this is needed #else - check(); + check(); // TODO double check #endif check, 16, 8>(); check(); diff --git a/sycl/unittests/helpers/PiMockPlugin.hpp b/sycl/unittests/helpers/PiMockPlugin.hpp index 05d3d8b70877d..ca3415dad2163 100644 --- a/sycl/unittests/helpers/PiMockPlugin.hpp +++ b/sycl/unittests/helpers/PiMockPlugin.hpp @@ -1157,5 +1157,3 @@ inline pi_result mock_piextEnqueueWriteHostPipe( *event = createDummyHandle(); return PI_SUCCESS; } - - From abbb0a3760239a2196715553fabdacba9fb1e558 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Mon, 28 Nov 2022 07:41:08 -0800 Subject: [PATCH 06/56] [SYCL] fix layout handler --- sycl/test/abi/layout_handler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sycl/test/abi/layout_handler.cpp b/sycl/test/abi/layout_handler.cpp index 4e07baead0642..2117e49502799 100644 --- a/sycl/test/abi/layout_handler.cpp +++ b/sycl/test/abi/layout_handler.cpp @@ -1,4 +1,5 @@ -// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s -o %t.out | FileCheck %s +// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s +// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s // REQUIRES: linux // UNSUPPORTED: libcxx From aa6cdffe52552626ae26032fd0317410c3c5799b Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Wed, 30 Mar 2022 09:26:16 -0700 Subject: [PATCH 07/56] [SYCL] Query pipe name from registration The pipe name is generated in integration footer and will be available to the runtime during device image registration. The runtime then store host pipe information in host piep map entry, which is kept track of in program manager. The host pipe information can be queried from the program manager through getHostPipeEntry using the host pipe pointer that is determined by its class member __pipe. (cherry picked from commit 44b7e73798e422aeb3e4cdd8a3204b96b86497d9) --- .../ext/intel/experimental/host_pipes.hpp | 19 ++++++++++++++++--- sycl/source/detail/host_pipe.cpp | 12 ++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp index 00c80f1007d22..295e82741ebee 100644 --- a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp @@ -49,9 +49,22 @@ class host_pipe<_name, _dataT, _propertiesT, std::enable_if_t>> { - static_assert( - sycl::ext::oneapi::experimental::is_property_list_v<_propertiesT>, - "Host pipe is available only through new property list"); + + struct +#ifdef __SYCL_DEVICE_ONLY__ + [[__sycl_detail__::add_ir_global_variable_attributes( + "sycl-host-pipe", + nullptr)]] [[__sycl_detail__:: + host_pipe]] [[__sycl_detail__:: + global_variable_allowed]] // may + // not be + // needed +#endif + __pipeType { + const char __p; + }; + + static constexpr __pipeType __pipe = {0}; public: using value_type = _dataT; diff --git a/sycl/source/detail/host_pipe.cpp b/sycl/source/detail/host_pipe.cpp index bc9fe33c555c7..d2b20eafe3306 100644 --- a/sycl/source/detail/host_pipe.cpp +++ b/sycl/source/detail/host_pipe.cpp @@ -7,6 +7,8 @@ //===----------------------------------------------------------------------===// #include +#include +#include namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { @@ -27,7 +29,10 @@ host_pipe<_name, _dataT, _propertiesT, } // TODO: get pipe name from the pipe registration _dataT data; - const std::string pipe_name = "pipename"; + const void *HostPipePtr = &__pipe; + detail::HostPipeMapEntry hostPipeEntry = + detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); + const std::string pipe_name = hostPipeEntry.MUniqueId; size_t size = 4; event e = q.submit([=](handler &CGH) { CGH.read_write_host_pipe(pipe_name, (void *)(&data), (size_t)size, false, @@ -50,7 +55,10 @@ void host_pipe< return; } // TODO: get pipe name from the pipe registration - const std::string pipe_name = "pipename"; + const void *HostPipePtr = &__pipe; + detail::HostPipeMapEntry hostPipeEntry = + detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); + const std::string pipe_name = hostPipeEntry.MUniqueId; const void *data_ptr = &data; size_t size = 4; event e = q.submit([=](handler &CGH) { From 0d9537554e426d95d3a20706a203c88fb24051b1 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Mon, 28 Nov 2022 11:00:55 -0800 Subject: [PATCH 08/56] [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. --- .../sycl/ext/intel/experimental/host_pipes.hpp | 2 +- sycl/source/detail/host_pipe_map_entry.hpp | 7 +++++++ .../source/detail/program_manager/program_manager.cpp | 2 ++ sycl/source/detail/scheduler/commands.cpp | 11 ++++++----- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp index 295e82741ebee..e2be91322a52c 100644 --- a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp @@ -89,7 +89,7 @@ class #ifdef __SYCL_DEVICE_ONLY__ static constexpr struct ConstantPipeStorage m_Storage = {m_Size, m_Alignment, - min_capacity}; + min_cap}; #endif // __SYCL_DEVICE_ONLY__ }; diff --git a/sycl/source/detail/host_pipe_map_entry.hpp b/sycl/source/detail/host_pipe_map_entry.hpp index 464856bcc133d..218d29c2009ed 100644 --- a/sycl/source/detail/host_pipe_map_entry.hpp +++ b/sycl/source/detail/host_pipe_map_entry.hpp @@ -8,6 +8,7 @@ #pragma once +#include #include #include @@ -21,6 +22,8 @@ struct HostPipeMapEntry { const void *MHostPipePtr; // Size of the underlying type in the host_pipe. std::uint32_t MHostPipeTSize; + // The device image that pipe is associated with + const RTDeviceBinaryImage *mDeviceImage; // Constructor only initializes with the pointer and ID. // Other members will be initialized later @@ -43,6 +46,10 @@ struct HostPipeMapEntry { assert(!MHostPipePtr && "Host pipe pointer has already been initialized."); MHostPipePtr = HostPipePtr; } + + void initialize(const RTDeviceBinaryImage *DeviceImage) { + mDeviceImage = DeviceImage; + } }; } // namespace detail diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 714771f0bf971..979e99ca2f232 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1335,12 +1335,14 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) { if (ExistingHostPipe != m_HostPipes.end()) { // If it has already been registered we update the information. ExistingHostPipe->second->initialize(TypeSize); + ExistingHostPipe->second->initialize(Img.get()); } else { // If it has not already been registered we create a new entry. // Note: Pointer to the host pipe is not available here, so it // cannot be set until registration happens. auto EntryUPtr = std::make_unique(HostPipe->Name, TypeSize); + EntryUPtr->initialize(Img.get()); m_HostPipes.emplace(HostPipe->Name, std::move(EntryUPtr)); } } diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index f238905868c5f..fd197555d46e8 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -2339,12 +2340,12 @@ pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, // 1. Encode this in the pipe registration // 2. Initialize the pipe registration from first kernel launch, but then this // will violate the spec - detail::OSModuleHandle M = - detail::OSUtil::getOSModuleHandle("HostPipeReadWriteKernelName"); + detail::HostPipeMapEntry *hostPipeEntry = + ProgramManager::getInstance().getHostPipeEntry(PipeName); RT::PiProgram Program = - sycl::detail::ProgramManager::getInstance().getBuiltPIProgram( - M, Queue->getContextImplPtr(), Queue->getDeviceImplPtr(), - "HostPipeReadWriteKernelName"); + ProgramManager::getInstance().createPIProgram( + *(hostPipeEntry->mDeviceImage), Queue->get_context(), + Queue->get_device()); // Get plugin for calling opencl functions const detail::plugin &Plugin = Queue->getPlugin(); From 26eec1a71ea0a69999c397c523918656b49493aa Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Tue, 19 Apr 2022 09:17:25 -0700 Subject: [PATCH 09/56] [SYCL][UNITTEST] Unit testing host pipe functionality This test mocks the following: 1. host pipe registration 2. device image registration 3. opencl function calls This aims to test: assuming the host pipe registration is correct the host pipe read and write should behave correctly, in this case, read and write the right data into the global variables. (cherry picked from commit 1f7d77fa9d0dc39cdc4b991a92f2a1a34b93c12b) Zibai fixed the conflicts --- .../ext/intel/experimental/host_pipes.hpp | 2 + sycl/include/sycl/sycl.hpp | 1 + sycl/source/detail/host_pipe.cpp | 6 +- sycl/unittests/CMakeLists.txt | 1 + sycl/unittests/pipes/CMakeLists.txt | 8 + .../pipes/host_pipe_registration.cpp | 154 ++++++++++++++++++ 6 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 sycl/unittests/pipes/CMakeLists.txt create mode 100644 sycl/unittests/pipes/host_pipe_registration.cpp diff --git a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp index e2be91322a52c..75eecb102a21f 100644 --- a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp @@ -73,6 +73,8 @@ class ? _propertiesT::template get_property().value : 0; + static const void *get_host_ptr() { return &__pipe; } + // Blocking pipes static _dataT read(queue & q, memory_order order = memory_order::seq_cst); static void write(queue & q, const _dataT &data, diff --git a/sycl/include/sycl/sycl.hpp b/sycl/include/sycl/sycl.hpp index f71e487dffdf1..42ee171f4f1a6 100644 --- a/sycl/include/sycl/sycl.hpp +++ b/sycl/include/sycl/sycl.hpp @@ -82,4 +82,5 @@ #include #include #include +#include #include diff --git a/sycl/source/detail/host_pipe.cpp b/sycl/source/detail/host_pipe.cpp index d2b20eafe3306..6335c3b70a664 100644 --- a/sycl/source/detail/host_pipe.cpp +++ b/sycl/source/detail/host_pipe.cpp @@ -33,9 +33,8 @@ host_pipe<_name, _dataT, _propertiesT, detail::HostPipeMapEntry hostPipeEntry = detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); const std::string pipe_name = hostPipeEntry.MUniqueId; - size_t size = 4; event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)(&data), (size_t)size, false, + CGH.read_write_host_pipe(pipe_name, (void *)(&data), sizeof(_dataT), false, true /* read */); }); e.wait(); @@ -60,9 +59,8 @@ void host_pipe< detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); const std::string pipe_name = hostPipeEntry.MUniqueId; const void *data_ptr = &data; - size_t size = 4; event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, (size_t)size, false, + CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, false /* write */); }); e.wait(); diff --git a/sycl/unittests/CMakeLists.txt b/sycl/unittests/CMakeLists.txt index 3dae4d715bd92..c4c808189a594 100644 --- a/sycl/unittests/CMakeLists.txt +++ b/sycl/unittests/CMakeLists.txt @@ -40,6 +40,7 @@ add_subdirectory(scheduler) add_subdirectory(stream) add_subdirectory(SYCL2020) add_subdirectory(thread_safety) +add_subdirectory(pipes) add_subdirectory(program_manager) add_subdirectory(assert) add_subdirectory(Extensions) diff --git a/sycl/unittests/pipes/CMakeLists.txt b/sycl/unittests/pipes/CMakeLists.txt new file mode 100644 index 0000000000000..9bec8a94609c1 --- /dev/null +++ b/sycl/unittests/pipes/CMakeLists.txt @@ -0,0 +1,8 @@ +set(CMAKE_CXX_EXTENSIONS OFF) + +add_sycl_unittest(PipeTests OBJECT + host_pipe_registration.cpp +) + +add_dependencies(PipeTests sycl) +target_include_directories(PipeTests PRIVATE SYSTEM ${sycl_inc_dir}) \ No newline at end of file diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp new file mode 100644 index 0000000000000..4fac5404f5670 --- /dev/null +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -0,0 +1,154 @@ +//==-------------- host_pipe_registration.cpp - Host pipe tests------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include +#include +#include +#include + +namespace { +using namespace sycl; +using pipe_prop = decltype(ext::oneapi::experimental::properties( + ext::intel::experimental::min_capacity<5>)); + +template struct pipe_id { + static constexpr unsigned id = ID; +}; + +class test_data_type { +public: + int num; +}; + +using test_host_pipe = + ext::intel::experimental::host_pipe, test_data_type, pipe_prop>; + +pi_device_binary_struct generate_device_binary() { + std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data + unittest::PiArray Entries = + unittest::makeEmptyKernels({"TestKernel"}); + unittest::PiPropertySet PropSet; + pi_device_binary_struct MBinaryDesc = pi_device_binary_struct{ + PI_DEVICE_BINARY_VERSION, + PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL, + PI_DEVICE_BINARY_TYPE_SPIRV, + __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, + "", + "", + nullptr, + nullptr, + &*Bin.begin(), + (&*Bin.begin()) + Bin.size(), + Entries.begin(), + Entries.end(), + PropSet.begin(), + PropSet.end(), + }; + return MBinaryDesc; +} +pi_event READ = reinterpret_cast(0); +pi_event WRITE = reinterpret_cast(1); +static constexpr test_data_type PipeReadVal = {8}; +static test_data_type PipeWriteVal = {0}; +pi_result redefinedEnqueueReadHostPipe(pi_queue, pi_program, const char *, + pi_bool, void *ptr, size_t, pi_uint32, + const pi_event *, pi_event *event) { + *(((test_data_type *)ptr)) = PipeReadVal; + *event = READ; + return PI_SUCCESS; +} +pi_result redefinedEnqueueWriteHostPipe(pi_queue, pi_program, const char *, + pi_bool, void *ptr, size_t, pi_uint32, + const pi_event *, pi_event *event) { + test_data_type tmp = {9}; + PipeWriteVal = tmp; + *event = WRITE; + return PI_SUCCESS; +} + +bool preparePiMock(platform &Plt) { + if (Plt.is_host()) { + std::cout << "Not run on host - no PI events created in that case" + << std::endl; + return false; + } + + unittest::PiMock Mock{Plt}; + Mock.redefine( + redefinedEnqueueReadHostPipe); + Mock.redefine( + redefinedEnqueueWriteHostPipe); + return true; +} + +class PipeTest : public ::testing::Test { +protected: + void SetUp() override { + platform Plt{default_selector()}; + if (!preparePiMock(Plt)) + return; + context Ctx{Plt.get_devices()[0]}; + queue Q{Ctx, default_selector()}; + plat = Plt; + ctx = Ctx; + q = Q; + + // Fake registration of host pipes + sycl::detail::host_pipe_map::add(test_host_pipe::get_host_ptr(), + "test_host_pipe_unique_id"); + // Fake registration of device image + static constexpr size_t NumberOfImages = 1; + pi_device_binary_struct MNativeImages[NumberOfImages]; + MNativeImages[0] = generate_device_binary(); + MAllBinaries = pi_device_binaries_struct{ + PI_DEVICE_BINARIES_VERSION, + NumberOfImages, + MNativeImages, + nullptr, // not used, put here for compatibility with OpenMP + nullptr, // not used, put here for compatibility with OpenMP + }; + __sycl_register_lib(&MAllBinaries); + } + + void TearDown() override { __sycl_unregister_lib(&MAllBinaries); } + + platform plat; + context ctx; + queue q; + pi_device_binaries_struct MAllBinaries; +}; + +TEST_F(PipeTest, Basic) { + const void *HostPipePtr = test_host_pipe::get_host_ptr(); + detail::HostPipeMapEntry *hostPipeEntry = + detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); + const std::string pipe_name = hostPipeEntry->MUniqueId; + test_data_type host_pipe_read_data = {}; + void *data_ptr = &host_pipe_read_data; + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, + true /* read */); + }); + e.wait(); + // auto host_pipe_read_data = test_host_pipe::read(q); + assert(host_pipe_read_data.num == PipeReadVal.num); + test_data_type tmp = {9}; + data_ptr = &tmp; + event e_write = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, + false /* write */); + }); + e_write.wait(); + // test_host_pipe::write(q, tmp); + assert(PipeWriteVal.num == 9); +} + +} // namespace From 6d98b5a63b076c41ce5313c56f5760fc343e1993 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Mon, 28 Nov 2022 13:30:33 -0800 Subject: [PATCH 10/56] [SYCL] update unit test to use newer PiMock --- .../ext/intel/experimental/host_pipes.hpp | 20 +- sycl/source/handler.cpp | 1 + .../pipes/host_pipe_registration.cpp | 210 +++++++++++++----- 3 files changed, 164 insertions(+), 67 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp index 75eecb102a21f..415d73ccdfac2 100644 --- a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp @@ -51,15 +51,17 @@ class is_property_list_v<_propertiesT>>> { struct -#ifdef __SYCL_DEVICE_ONLY__ - [[__sycl_detail__::add_ir_global_variable_attributes( - "sycl-host-pipe", - nullptr)]] [[__sycl_detail__:: - host_pipe]] [[__sycl_detail__:: - global_variable_allowed]] // may - // not be - // needed -#endif +// Commented out since the host_pipe attribute is not introduced by the front end yet. +// Confirm with Rob +// #ifdef __SYCL_DEVICE_ONLY__ +// [[__sycl_detail__::add_ir_attributes_global_variable( +// "sycl-host-pipe", +// nullptr)]] [[__sycl_detail__:: +// host_pipe]] [[__sycl_detail__:: +// global_variable_allowed]] // may +// // not be +// // needed +// #endif __pipeType { const char __p; }; diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index e3ce029cbda8d..0d6814ec041e5 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -863,6 +863,7 @@ id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) { void handler::read_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, bool Block, bool Read) { throwIfActionIsCreated(); + std::clog << "Zibai remove this read_write_host_pipe is invoked \n"; HostPipeName = Name; HostPipePtr = Ptr; HostPipeTypeSize = Size; diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 4fac5404f5670..c11c59a94c46a 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -10,11 +10,54 @@ #include #include -#include #include #include -namespace { +template class TestKernel; + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { +namespace detail { +template struct KernelInfo> { + static constexpr unsigned getNumParams() { return 0; } + static const kernel_param_desc_t &getParamDesc(int) { + static kernel_param_desc_t Dummy; + return Dummy; + } + static constexpr const char *getName() { return "TestKernel"; } + static constexpr bool isESIMD() { return false; } + static constexpr bool callsThisItem() { return false; } + static constexpr bool callsAnyThisFreeFunction() { return false; } + static constexpr int64_t getKernelSize() { return KernelSize; } +}; + +} // namespace detail +} // __SYCL_INLINE_VER_NAMESPACE(_V1) +} // namespace sycl + +static sycl::unittest::PiImage generateDefaultImage() { + using namespace sycl::unittest; + + PiPropertySet PropSet; + + std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data + + PiArray Entries = makeEmptyKernels({"TestKernel"}); + + PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format + __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec + "", // Compile options + "", // Link options + std::move(Bin), + std::move(Entries), + std::move(PropSet)}; + + return Img; +} + +static sycl::unittest::PiImage Img = generateDefaultImage(); +static sycl::unittest::PiImageArray<1> ImgArray{&Img}; + using namespace sycl; using pipe_prop = decltype(ext::oneapi::experimental::properties( ext::intel::experimental::min_capacity<5>)); @@ -31,29 +74,30 @@ class test_data_type { using test_host_pipe = ext::intel::experimental::host_pipe, test_data_type, pipe_prop>; -pi_device_binary_struct generate_device_binary() { - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - unittest::PiArray Entries = - unittest::makeEmptyKernels({"TestKernel"}); - unittest::PiPropertySet PropSet; - pi_device_binary_struct MBinaryDesc = pi_device_binary_struct{ - PI_DEVICE_BINARY_VERSION, - PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL, - PI_DEVICE_BINARY_TYPE_SPIRV, - __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, - "", - "", - nullptr, - nullptr, - &*Bin.begin(), - (&*Bin.begin()) + Bin.size(), - Entries.begin(), - Entries.end(), - PropSet.begin(), - PropSet.end(), - }; - return MBinaryDesc; -} +// pi_device_binary_struct generate_device_binary() { +// std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data +// unittest::PiArray Entries = +// unittest::makeEmptyKernels({"TestKernel"}); +// unittest::PiPropertySet PropSet; +// pi_device_binary_struct MBinaryDesc = pi_device_binary_struct{ +// PI_DEVICE_BINARY_VERSION, +// PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL, +// PI_DEVICE_BINARY_TYPE_SPIRV, +// __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, +// "", +// "", +// nullptr, +// nullptr, +// &*Bin.begin(), +// (&*Bin.begin()) + Bin.size(), +// Entries.begin(), +// Entries.end(), +// PropSet.begin(), +// PropSet.end(), +// }; +// return MBinaryDesc; +// } + pi_event READ = reinterpret_cast(0); pi_event WRITE = reinterpret_cast(1); static constexpr test_data_type PipeReadVal = {8}; @@ -74,75 +118,127 @@ pi_result redefinedEnqueueWriteHostPipe(pi_queue, pi_program, const char *, return PI_SUCCESS; } -bool preparePiMock(platform &Plt) { - if (Plt.is_host()) { - std::cout << "Not run on host - no PI events created in that case" - << std::endl; - return false; - } - - unittest::PiMock Mock{Plt}; +void preparePiMock(unittest::PiMock &Mock) { Mock.redefine( redefinedEnqueueReadHostPipe); Mock.redefine( redefinedEnqueueWriteHostPipe); - return true; } +// class PipeTest : public ::testing::Test { +// protected: +// void SetUp() override { + // std::cerr << "Zibai started to setup" << std::endl; + // sycl::unittest::PiMock Mock; + // sycl::platform Plt = Mock.getPlatform(); + // std::cerr << "Zibai started calling getPlatform" << std::endl; + // preparePiMock(Mock); + // std::cerr << "Zibai started calling get_devices" << std::endl; + // const sycl::device Dev = Plt.get_devices()[0]; + // std::cerr << "Zibai finished calling get_devices" << std::endl; + // sycl::context Ctx{Dev}; + // std::cerr << "Zibai finished calling Ctx" << std::endl; + // sycl::queue Q{Ctx, Dev}; + // std::cerr << "Zibai finished BUILDING queueu" << std::endl; + // plat = Plt; + // ctx = Ctx; + // q = Q; + + // // Fake registration of host pipes + // sycl::detail::host_pipe_map::add(test_host_pipe::get_host_ptr(), + // "test_host_pipe_unique_id"); + // // Fake registration of device image + // static constexpr size_t NumberOfImages = 1; + // pi_device_binary_struct MNativeImages[NumberOfImages]; + // std::cerr << "Zibai started generate_device_binary" << std::endl; + // MNativeImages[0] = generate_device_binary(); + // std::cerr << "Zibai finished generate_device_binary" << std::endl;; + // MAllBinaries = pi_device_binaries_struct{ + // PI_DEVICE_BINARIES_VERSION, + // NumberOfImages, + // MNativeImages, + // nullptr, // not used, put here for compatibility with OpenMP + // nullptr, // not used, put here for compatibility with OpenMP + // }; + // __sycl_register_lib(&MAllBinaries); +// } + +// void TearDown() override { __sycl_unregister_lib(&MAllBinaries); } + +// platform plat; +// context ctx; +// queue q; +// pi_device_binaries_struct MAllBinaries; +// }; + + class PipeTest : public ::testing::Test { +public: + PipeTest() : Mock{}, Plt{Mock.getPlatform()} {} + protected: void SetUp() override { - platform Plt{default_selector()}; - if (!preparePiMock(Plt)) - return; - context Ctx{Plt.get_devices()[0]}; - queue Q{Ctx, default_selector()}; - plat = Plt; + std::clog << "Zibai started the setup clog\n"; + preparePiMock(Mock); + const sycl::device Dev = Plt.get_devices()[0]; + sycl::context Ctx{Dev}; + sycl::queue Q{Ctx, Dev}; ctx = Ctx; q = Q; - // Fake registration of host pipes sycl::detail::host_pipe_map::add(test_host_pipe::get_host_ptr(), "test_host_pipe_unique_id"); // Fake registration of device image - static constexpr size_t NumberOfImages = 1; - pi_device_binary_struct MNativeImages[NumberOfImages]; - MNativeImages[0] = generate_device_binary(); - MAllBinaries = pi_device_binaries_struct{ - PI_DEVICE_BINARIES_VERSION, - NumberOfImages, - MNativeImages, - nullptr, // not used, put here for compatibility with OpenMP - nullptr, // not used, put here for compatibility with OpenMP - }; - __sycl_register_lib(&MAllBinaries); + // static constexpr size_t NumberOfImages = 1; + // pi_device_binary_struct MNativeImages[NumberOfImages]; + // MNativeImages[0] = generate_device_binary(); + // std::clog << "Zibai finished generate_device_binary \n"; + // MAllBinaries = pi_device_binaries_struct{ + // PI_DEVICE_BINARIES_VERSION, + // NumberOfImages, + // MNativeImages, + // nullptr, // not used, put here for compatibility with OpenMP + // nullptr, // not used, put here for compatibility with OpenMP + // }; + //__sycl_register_lib(&MAllBinaries); // This is gving some problems!! } - void TearDown() override { __sycl_unregister_lib(&MAllBinaries); } + // void TearDown() override { __sycl_unregister_lib(&MAllBinaries); } - platform plat; +protected: + unittest::PiMock Mock; + sycl::platform Plt; context ctx; queue q; pi_device_binaries_struct MAllBinaries; }; + + TEST_F(PipeTest, Basic) { + std::clog << "Zibai started the get_host_ptr\n"; const void *HostPipePtr = test_host_pipe::get_host_ptr(); + std::clog << "Zibai started the hostPipeEntry\n"; detail::HostPipeMapEntry *hostPipeEntry = detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); const std::string pipe_name = hostPipeEntry->MUniqueId; + std::clog << "Zibai what is the pipe_name " << pipe_name << "\n"; // this part is fine test_data_type host_pipe_read_data = {}; void *data_ptr = &host_pipe_read_data; - event e = q.submit([=](handler &CGH) { + std::clog << "Zibai started the q submit for read\n"; + event e = q.submit([&](handler &CGH) { CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, true /* read */); }); + std::clog << "Zibai started the wait for read\n"; e.wait(); + std::clog << "Zibai started the assert\n"; // auto host_pipe_read_data = test_host_pipe::read(q); assert(host_pipe_read_data.num == PipeReadVal.num); test_data_type tmp = {9}; data_ptr = &tmp; - event e_write = q.submit([=](handler &CGH) { + std::clog << "Zibai started the q submit for write\n"; + event e_write = q.submit([&](handler &CGH) { CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, false /* write */); }); @@ -150,5 +246,3 @@ TEST_F(PipeTest, Basic) { // test_host_pipe::write(q, tmp); assert(PipeWriteVal.num == 9); } - -} // namespace From 252b403501adbc4b40320113a7cb3f0542a5f447 Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Thu, 21 Apr 2022 11:53:47 -0700 Subject: [PATCH 11/56] remove type trait (cherry picked from commit 2eaa02cc17e702524de60f2240c0a535eaf5c140) --- .../ext/intel/experimental/host_pipes.hpp | 37 ++---- .../intel/experimental/pipe_properties.hpp | 12 +- sycl/include/sycl/sycl.hpp | 4 +- sycl/source/detail/host_pipe.cpp | 15 +-- sycl/source/detail/host_pipe_map_entry.hpp | 2 +- .../program_manager/program_manager.cpp | 2 + sycl/source/detail/scheduler/commands.cpp | 7 +- sycl/source/handler.cpp | 2 +- .../pipes/host_pipe_registration.cpp | 116 +++--------------- 9 files changed, 50 insertions(+), 147 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp index 415d73ccdfac2..3d52d2cca8abe 100644 --- a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp @@ -26,15 +26,6 @@ namespace ext { namespace intel { namespace experimental { -template -class host_pipe { - static_assert( - sycl::ext::oneapi::experimental::is_property_list_v<_propertiesT>, - "Host pipe is available only through new property list"); -}; - using default_pipe_properties = decltype(sycl::ext::oneapi::experimental::properties(min_capacity<0>)); @@ -46,23 +37,21 @@ class #endif // TODO: change name to pipe, and merge into the existing pipe // implementation - host_pipe<_name, _dataT, _propertiesT, - std::enable_if_t>> { + host_pipe { struct -// Commented out since the host_pipe attribute is not introduced by the front end yet. -// Confirm with Rob -// #ifdef __SYCL_DEVICE_ONLY__ -// [[__sycl_detail__::add_ir_attributes_global_variable( -// "sycl-host-pipe", -// nullptr)]] [[__sycl_detail__:: -// host_pipe]] [[__sycl_detail__:: -// global_variable_allowed]] // may -// // not be -// // needed -// #endif - __pipeType { +// Commented out since the host_pipe attribute is not introduced by the front +// end yet. Confirm with Rob +#ifdef __SYCL_DEVICE_ONLY__ + [[__sycl_detail__::add_ir_attributes_global_variable( + "sycl-host-pipe", + nullptr)]] [[__sycl_detail__:: + host_pipe]] [[__sycl_detail__:: + global_variable_allowed]] // may + // not be + // needed +#endif + __pipeType { const char __p; }; diff --git a/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp index 215a1d7ee8e53..aa26cf7406cb4 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp @@ -41,28 +41,28 @@ struct uses_valid_key { template using value_t = oneapi::experimental::property_value>; + std::bool_constant>; }; struct uses_ready_key { template using value_t = oneapi::experimental::property_value>; + std::bool_constant>; }; struct in_csr_key { template using value_t = oneapi::experimental::property_value>; + std::bool_constant>; }; struct first_symbol_in_high_order_bits_key { template - using value_t = oneapi::experimental::property_value< - first_symbol_in_high_order_bits_key, - sycl::detail::bool_constant>; + using value_t = + oneapi::experimental::property_value>; }; enum class protocol_name : std::uint16_t { AVALON, AXI }; diff --git a/sycl/include/sycl/sycl.hpp b/sycl/include/sycl/sycl.hpp index 42ee171f4f1a6..44be5b32a8e4f 100644 --- a/sycl/include/sycl/sycl.hpp +++ b/sycl/include/sycl/sycl.hpp @@ -67,6 +67,8 @@ #include #include #include +#include +#include #include #include #include @@ -82,5 +84,3 @@ #include #include #include -#include -#include diff --git a/sycl/source/detail/host_pipe.cpp b/sycl/source/detail/host_pipe.cpp index 6335c3b70a664..f62ef794eb797 100644 --- a/sycl/source/detail/host_pipe.cpp +++ b/sycl/source/detail/host_pipe.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include #include #include +#include namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { @@ -17,10 +17,8 @@ namespace intel { namespace experimental { template -_dataT -host_pipe<_name, _dataT, _propertiesT, - std::enable_if_t>>::read(queue &q, memory_order order) { +_dataT host_pipe<_name, _dataT, _propertiesT>::read(queue &q, + memory_order order) { const device Dev = q.get_device(); bool IsReadPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); @@ -42,11 +40,8 @@ host_pipe<_name, _dataT, _propertiesT, } template -void host_pipe< - _name, _dataT, _propertiesT, - std::enable_if_t>>::write(queue &q, const _dataT &data, - memory_order order) { +void host_pipe<_name, _dataT, _propertiesT>::write(queue &q, const _dataT &data, + memory_order order) { const device Dev = q.get_device(); bool IsReadPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); diff --git a/sycl/source/detail/host_pipe_map_entry.hpp b/sycl/source/detail/host_pipe_map_entry.hpp index 218d29c2009ed..2a7412e167990 100644 --- a/sycl/source/detail/host_pipe_map_entry.hpp +++ b/sycl/source/detail/host_pipe_map_entry.hpp @@ -8,8 +8,8 @@ #pragma once -#include #include +#include #include namespace sycl { diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 979e99ca2f232..eff8f548811fe 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1667,6 +1667,8 @@ std::vector ProgramManager::getDeviceGlobalEntries( } return FoundEntries; +} + void ProgramManager::addOrInitHostPipeEntry(const void *HostPipePtr, const char *UniqueId) { std::lock_guard HostPipesGuard(m_HostPipesMutex); diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index fd197555d46e8..a06540fc742b9 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -2342,10 +2342,9 @@ pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, // will violate the spec detail::HostPipeMapEntry *hostPipeEntry = ProgramManager::getInstance().getHostPipeEntry(PipeName); - RT::PiProgram Program = - ProgramManager::getInstance().createPIProgram( - *(hostPipeEntry->mDeviceImage), Queue->get_context(), - Queue->get_device()); + RT::PiProgram Program = ProgramManager::getInstance().createPIProgram( + *(hostPipeEntry->mDeviceImage), Queue->get_context(), + Queue->get_device()); // Get plugin for calling opencl functions const detail::plugin &Plugin = Queue->getPlugin(); diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 0d6814ec041e5..431ae7abe5807 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -862,7 +862,7 @@ id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) { void handler::read_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, bool Block, bool Read) { - throwIfActionIsCreated(); + // throwIfActionIsCreated(); // Need this?? Zibai std::clog << "Zibai remove this read_write_host_pipe is invoked \n"; HostPipeName = Name; HostPipePtr = Ptr; diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index c11c59a94c46a..0f1a8281ecc3b 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include #include +#include #include #include @@ -55,15 +55,12 @@ static sycl::unittest::PiImage generateDefaultImage() { return Img; } -static sycl::unittest::PiImage Img = generateDefaultImage(); -static sycl::unittest::PiImageArray<1> ImgArray{&Img}; - using namespace sycl; using pipe_prop = decltype(ext::oneapi::experimental::properties( ext::intel::experimental::min_capacity<5>)); template struct pipe_id { - static constexpr unsigned id = ID; + static constexpr unsigned id = ID; }; class test_data_type { @@ -74,30 +71,6 @@ class test_data_type { using test_host_pipe = ext::intel::experimental::host_pipe, test_data_type, pipe_prop>; -// pi_device_binary_struct generate_device_binary() { -// std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data -// unittest::PiArray Entries = -// unittest::makeEmptyKernels({"TestKernel"}); -// unittest::PiPropertySet PropSet; -// pi_device_binary_struct MBinaryDesc = pi_device_binary_struct{ -// PI_DEVICE_BINARY_VERSION, -// PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL, -// PI_DEVICE_BINARY_TYPE_SPIRV, -// __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, -// "", -// "", -// nullptr, -// nullptr, -// &*Bin.begin(), -// (&*Bin.begin()) + Bin.size(), -// Entries.begin(), -// Entries.end(), -// PropSet.begin(), -// PropSet.end(), -// }; -// return MBinaryDesc; -// } - pi_event READ = reinterpret_cast(0); pi_event WRITE = reinterpret_cast(1); static constexpr test_data_type PipeReadVal = {8}; @@ -125,111 +98,56 @@ void preparePiMock(unittest::PiMock &Mock) { redefinedEnqueueWriteHostPipe); } -// class PipeTest : public ::testing::Test { -// protected: -// void SetUp() override { - // std::cerr << "Zibai started to setup" << std::endl; - // sycl::unittest::PiMock Mock; - // sycl::platform Plt = Mock.getPlatform(); - // std::cerr << "Zibai started calling getPlatform" << std::endl; - // preparePiMock(Mock); - // std::cerr << "Zibai started calling get_devices" << std::endl; - // const sycl::device Dev = Plt.get_devices()[0]; - // std::cerr << "Zibai finished calling get_devices" << std::endl; - // sycl::context Ctx{Dev}; - // std::cerr << "Zibai finished calling Ctx" << std::endl; - // sycl::queue Q{Ctx, Dev}; - // std::cerr << "Zibai finished BUILDING queueu" << std::endl; - // plat = Plt; - // ctx = Ctx; - // q = Q; - - // // Fake registration of host pipes - // sycl::detail::host_pipe_map::add(test_host_pipe::get_host_ptr(), - // "test_host_pipe_unique_id"); - // // Fake registration of device image - // static constexpr size_t NumberOfImages = 1; - // pi_device_binary_struct MNativeImages[NumberOfImages]; - // std::cerr << "Zibai started generate_device_binary" << std::endl; - // MNativeImages[0] = generate_device_binary(); - // std::cerr << "Zibai finished generate_device_binary" << std::endl;; - // MAllBinaries = pi_device_binaries_struct{ - // PI_DEVICE_BINARIES_VERSION, - // NumberOfImages, - // MNativeImages, - // nullptr, // not used, put here for compatibility with OpenMP - // nullptr, // not used, put here for compatibility with OpenMP - // }; - // __sycl_register_lib(&MAllBinaries); -// } - -// void TearDown() override { __sycl_unregister_lib(&MAllBinaries); } - -// platform plat; -// context ctx; -// queue q; -// pi_device_binaries_struct MAllBinaries; -// }; - - class PipeTest : public ::testing::Test { public: PipeTest() : Mock{}, Plt{Mock.getPlatform()} {} protected: void SetUp() override { - std::clog << "Zibai started the setup clog\n"; + std::clog << "Zibai started the setup()\n"; preparePiMock(Mock); const sycl::device Dev = Plt.get_devices()[0]; sycl::context Ctx{Dev}; sycl::queue Q{Ctx, Dev}; ctx = Ctx; q = Q; - // Fake registration of host pipes - sycl::detail::host_pipe_map::add(test_host_pipe::get_host_ptr(), - "test_host_pipe_unique_id"); - // Fake registration of device image - // static constexpr size_t NumberOfImages = 1; - // pi_device_binary_struct MNativeImages[NumberOfImages]; - // MNativeImages[0] = generate_device_binary(); - // std::clog << "Zibai finished generate_device_binary \n"; - // MAllBinaries = pi_device_binaries_struct{ - // PI_DEVICE_BINARIES_VERSION, - // NumberOfImages, - // MNativeImages, - // nullptr, // not used, put here for compatibility with OpenMP - // nullptr, // not used, put here for compatibility with OpenMP - // }; - //__sycl_register_lib(&MAllBinaries); // This is gving some problems!! } - // void TearDown() override { __sycl_unregister_lib(&MAllBinaries); } - protected: unittest::PiMock Mock; sycl::platform Plt; context ctx; queue q; - pi_device_binaries_struct MAllBinaries; }; +TEST_F(PipeTest, Basic) { + // Fake registration of host pipes + sycl::detail::host_pipe_map::add(test_host_pipe::get_host_ptr(), + "test_host_pipe_unique_id"); + + // Device registration + std::clog << "Zibai started the Device registration\n"; + static sycl::unittest::PiImage Img = generateDefaultImage(); + static sycl::unittest::PiImageArray<1> ImgArray{&Img}; -TEST_F(PipeTest, Basic) { std::clog << "Zibai started the get_host_ptr\n"; const void *HostPipePtr = test_host_pipe::get_host_ptr(); std::clog << "Zibai started the hostPipeEntry\n"; detail::HostPipeMapEntry *hostPipeEntry = detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); const std::string pipe_name = hostPipeEntry->MUniqueId; - std::clog << "Zibai what is the pipe_name " << pipe_name << "\n"; // this part is fine + std::clog << "Zibai what is the pipe_name " << pipe_name + << "\n"; // this part is fine test_data_type host_pipe_read_data = {}; void *data_ptr = &host_pipe_read_data; std::clog << "Zibai started the q submit for read\n"; event e = q.submit([&](handler &CGH) { CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, true /* read */); + // CGH.single_task>([&]() {}); }); + std::clog << "Zibai started the wait for read\n"; e.wait(); std::clog << "Zibai started the assert\n"; @@ -245,4 +163,4 @@ TEST_F(PipeTest, Basic) { e_write.wait(); // test_host_pipe::write(q, tmp); assert(PipeWriteVal.num == 9); -} +} \ No newline at end of file From 2821aaeb2eff380170f7fb61cc1cdab0f3ab5177 Mon Sep 17 00:00:00 2001 From: "Ho, Robert" Date: Fri, 20 Jan 2023 11:43:13 -0800 Subject: [PATCH 12/56] Move host pipe additions into existing pipe class --- .../intel/experimental/pipe_properties.hpp | 33 +++------ .../sycl/ext/intel/experimental/pipes.hpp | 71 ++++++++++++++++--- 2 files changed, 70 insertions(+), 34 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp index aa26cf7406cb4..226a14212aee2 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp @@ -44,13 +44,6 @@ struct uses_valid_key { std::bool_constant>; }; -struct uses_ready_key { - template - using value_t = - oneapi::experimental::property_value>; -}; - struct in_csr_key { template using value_t = @@ -65,7 +58,12 @@ struct first_symbol_in_high_order_bits_key { std::bool_constant>; }; -enum class protocol_name : std::uint16_t { AVALON, AXI }; +enum class protocol_name : std::uint16_t { + AVALON_STREAMING = 0, + AVALON_STREAMING_USES_READY = 1, + AVALON_MM = 2, + AVALON_MM_USES_READY = 3 }; + struct protocol_key { template using value_t = oneapi::experimental::property_value< @@ -86,11 +84,6 @@ inline constexpr uses_valid_key::value_t uses_valid; inline constexpr uses_valid_key::value_t uses_valid_on; inline constexpr uses_valid_key::value_t uses_valid_off; -template -inline constexpr uses_ready_key::value_t uses_ready; -inline constexpr uses_ready_key::value_t uses_ready_on; -inline constexpr uses_ready_key::value_t uses_ready_off; - template inline constexpr in_csr_key::value_t in_csr; inline constexpr in_csr_key::value_t in_csr_on; inline constexpr in_csr_key::value_t in_csr_off; @@ -105,8 +98,10 @@ inline constexpr first_symbol_in_high_order_bits_key::value_t template inline constexpr protocol_key::value_t protocol; -inline constexpr protocol_key::value_t protocol_avalon; -inline constexpr protocol_key::value_t protocol_axi; +inline constexpr protocol_key::value_t protocol_avalon_streaming; +inline constexpr protocol_key::value_t protocol_avalon_streaming_uses_ready; +inline constexpr protocol_key::value_t protocol_avalon_mm; +inline constexpr protocol_key::value_t protocol_avalon_mm_uses_ready; } // namespace experimental } // namespace intel @@ -126,8 +121,6 @@ struct is_property_key template <> struct is_property_key : std::true_type {}; template <> -struct is_property_key : std::true_type {}; -template <> struct is_property_key : std::true_type {}; template <> struct is_property_key @@ -148,9 +141,6 @@ template <> struct PropertyToKind { template <> struct PropertyToKind { static constexpr PropKind Kind = PropKind::UsesValid; }; -template <> struct PropertyToKind { - static constexpr PropKind Kind = PropKind::UsesReady; -}; template <> struct PropertyToKind { static constexpr PropKind Kind = PropKind::ImplementInCSR; }; @@ -176,9 +166,6 @@ template <> struct IsCompileTimeProperty : std::true_type {}; template <> -struct IsCompileTimeProperty - : std::true_type {}; -template <> struct IsCompileTimeProperty : std::true_type { }; template <> diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index b327e1fdd167d..752b9129ac9d7 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -9,6 +9,7 @@ #pragma once #include "fpga_utils.hpp" +#include "pipe_properties.hpp" #include #include #include @@ -19,21 +20,52 @@ namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { namespace ext::intel::experimental { +namespace detail { +template +struct ValueOrDefault { + template static constexpr ValT get(ValT Default) { + return Default; + } +}; + +template +struct ValueOrDefault< + Properties, PropertyKey, + std::enable_if_t< + sycl::ext::oneapi::experimental::is_property_list_v && + Properties::template has_property()>> { + template static constexpr ValT get(ValT) { + return Properties::template get_property().value; + } +}; +} // namespace detail + template class pipe { - static_assert(std::is_same_v<_propertiesT, - decltype(oneapi::experimental::properties{})>, - "experimental pipe properties are not yet implemented"); -}; - -template -class pipe<_name, _dataT, _min_capacity, _propertiesT, - std::enable_if_t>> { public: +#ifdef __SYCL_DEVICE_ONLY__ + struct + [[__sycl_detail__::add_ir_attributes_global_variable( + "sycl-host-pipe", nullptr)]][[__sycl_detail__::sycl_type(host_pipe)]] + ConstantPipeStorageExp : ConstantPipeStorage { + int32_t _ReadyLatency; + int32_t _BitsPerSymbol; + bool _UsesValid; + bool _FirstSymInHighOrderBits; + protocol_name _Protocol; + }; +#endif + // Non-blocking pipes + + // Host API + static _dataT read(queue & q, bool &success_code, + memory_order order = memory_order::seq_cst); + static void write(queue & q, const _dataT &data, bool &success_code, + memory_order order = memory_order::seq_cst); + // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V // friendly LLVM IR. template @@ -133,6 +165,12 @@ class pipe<_name, _dataT, _min_capacity, _propertiesT, } // Blocking pipes + + // Host API + static _dataT read(queue & q, memory_order order = memory_order::seq_cst); + static void write(queue & q, const _dataT &data, + memory_order order = memory_order::seq_cst); + // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V // friendly LLVM IR. template @@ -230,9 +268,20 @@ class pipe<_name, _dataT, _min_capacity, _propertiesT, static constexpr int32_t m_Size = sizeof(_dataT); static constexpr int32_t m_Alignment = alignof(_dataT); static constexpr int32_t m_Capacity = _min_capacity; + + static constexpr int32_t m_ready_latency = detail::ValueOrDefault<_propertiesT, ready_latency_key>::template get(0); + static constexpr int32_t m_bits_per_symbol = detail::ValueOrDefault<_propertiesT, bits_per_symbol_key>::template get(0); + static constexpr bool m_uses_valid = detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get(0); + static constexpr bool m_first_symbol_in_high_order_bits = detail::ValueOrDefault<_propertiesT, first_symbol_in_high_order_bits_key>::template get(0); + static constexpr protocol_name m_protocol = detail::ValueOrDefault<_propertiesT, protocol_key>::template get(protocol_name::AVALON_STREAMING); + + #ifdef __SYCL_DEVICE_ONLY__ - static constexpr struct ConstantPipeStorage m_Storage = {m_Size, m_Alignment, - m_Capacity}; + static constexpr struct ConstantPipeStorageExp m_Storage = { { m_Size, m_Alignment, + m_Capacity}, m_ready_latency, + m_bits_per_symbol, m_uses_valid, + m_first_symbol_in_high_order_bits, + m_protocol }; // FPGA BE will recognize this function and extract its arguments. // TODO: Pass latency control parameters via the __spirv_* builtin when ready. From 8fd64af2c0b1da2e3836f2562c810d49e3ff084f Mon Sep 17 00:00:00 2001 From: "Ho, Robert" Date: Tue, 31 Jan 2023 06:59:34 -0800 Subject: [PATCH 13/56] Define m_Storage on host and make public --- sycl/include/sycl/detail/cg.hpp | 3 +++ .../sycl/ext/intel/experimental/pipes.hpp | 20 +++++++++++++------ sycl/include/sycl/sycl.hpp | 4 ++-- sycl/plugins/cuda/pi_cuda.cpp | 2 ++ sycl/plugins/hip/pi_hip.cpp | 2 ++ sycl/plugins/level_zero/pi_level_zero.cpp | 2 ++ sycl/plugins/opencl/pi_opencl.cpp | 2 ++ sycl/source/handler.cpp | 1 + 8 files changed, 28 insertions(+), 8 deletions(-) diff --git a/sycl/include/sycl/detail/cg.hpp b/sycl/include/sycl/detail/cg.hpp index cba29f866d40a..e83c4a21c9220 100644 --- a/sycl/include/sycl/detail/cg.hpp +++ b/sycl/include/sycl/detail/cg.hpp @@ -491,6 +491,9 @@ class CGMemset2DUSM : public CG { size_t getWidth() const { return MWidth; } size_t getHeight() const { return MHeight; } char getValue() const { return MValue; } + +}; + /// "ReadWriteHostPipe" command group class. class CGReadWriteHostPipe : public CG { std::string PipeName; diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 752b9129ac9d7..a5660a766385e 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -45,18 +45,22 @@ template class pipe { public: -#ifdef __SYCL_DEVICE_ONLY__ struct +#ifdef __SYCL_DEVICE_ONLY__ [[__sycl_detail__::add_ir_attributes_global_variable( "sycl-host-pipe", nullptr)]][[__sycl_detail__::sycl_type(host_pipe)]] - ConstantPipeStorageExp : ConstantPipeStorage { +#endif // __SYCL_DEVICE_ONLY___ + ConstantPipeStorageExp +#ifdef __SYCL_DEVICE_ONLY__ + : ConstantPipeStorage +#endif // __SYCL_DEVICE_ONLY___ + { int32_t _ReadyLatency; int32_t _BitsPerSymbol; bool _UsesValid; bool _FirstSymInHighOrderBits; protocol_name _Protocol; }; -#endif // Non-blocking pipes @@ -275,14 +279,18 @@ class pipe { static constexpr bool m_first_symbol_in_high_order_bits = detail::ValueOrDefault<_propertiesT, first_symbol_in_high_order_bits_key>::template get(0); static constexpr protocol_name m_protocol = detail::ValueOrDefault<_propertiesT, protocol_key>::template get(protocol_name::AVALON_STREAMING); - +public: + static constexpr struct ConstantPipeStorageExp m_Storage = { #ifdef __SYCL_DEVICE_ONLY__ - static constexpr struct ConstantPipeStorageExp m_Storage = { { m_Size, m_Alignment, - m_Capacity}, m_ready_latency, + { m_Size, m_Alignment, m_Capacity }, +#endif // __SYCL_DEVICE_ONLY___ + m_ready_latency, m_bits_per_symbol, m_uses_valid, m_first_symbol_in_high_order_bits, m_protocol }; +#ifdef __SYCL_DEVICE_ONLY__ +private: // FPGA BE will recognize this function and extract its arguments. // TODO: Pass latency control parameters via the __spirv_* builtin when ready. template diff --git a/sycl/include/sycl/sycl.hpp b/sycl/include/sycl/sycl.hpp index 44be5b32a8e4f..0a64d2cf6b504 100644 --- a/sycl/include/sycl/sycl.hpp +++ b/sycl/include/sycl/sycl.hpp @@ -63,12 +63,12 @@ #include #endif #include +#include +#include #include #include #include #include -#include -#include #include #include #include diff --git a/sycl/plugins/cuda/pi_cuda.cpp b/sycl/plugins/cuda/pi_cuda.cpp index d8d1284744d70..badf786e25848 100644 --- a/sycl/plugins/cuda/pi_cuda.cpp +++ b/sycl/plugins/cuda/pi_cuda.cpp @@ -5550,6 +5550,8 @@ pi_result cuda_piextEnqueueDeviceGlobalVariableRead( result = error; } return result; +} + /// Host Pipes pi_result cuda_piextEnqueueReadHostPipe( pi_queue queue, pi_program program, const char *pipe_symbol, diff --git a/sycl/plugins/hip/pi_hip.cpp b/sycl/plugins/hip/pi_hip.cpp index 0903838fe4148..ac5f2f62e2b80 100644 --- a/sycl/plugins/hip/pi_hip.cpp +++ b/sycl/plugins/hip/pi_hip.cpp @@ -5317,6 +5317,8 @@ pi_result hip_piextEnqueueDeviceGlobalVariableRead( sycl::detail::pi::die( "hip_piextEnqueueDeviceGlobalVariableRead not implemented"); +} + /// Host Pipes pi_result hip_piextEnqueueReadHostPipe(pi_queue queue, pi_program program, const char *pipe_symbol, diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index cde8bfb45b995..22c5bfe946036 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -7933,6 +7933,8 @@ pi_result piextEnqueueDeviceGlobalVariableRead( PI_COMMAND_TYPE_DEVICE_GLOBAL_VARIABLE_READ, Queue, Dst, BlockingRead, Count, pi_cast(GlobalVarPtr) + Offset, NumEventsInWaitList, EventsWaitList, Event, PreferCopyEngine); + +} /// API for Read from host pipe. /// /// \param Queue is the queue diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index 1a123ff1e8364..ce7b9f9116085 100644 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -1687,6 +1687,8 @@ pi_result piextEnqueueDeviceGlobalVariableRead( blocking_read, count, offset, dst, num_events_in_wait_list, cast(event_wait_list), cast(event)); return cast(Res); +} + pi_result piextEnqueueReadHostPipe(pi_queue queue, pi_program program, const char *pipe_symbol, pi_bool blocking, void *ptr, size_t size, diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 431ae7abe5807..960382fc0cecc 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -859,6 +859,7 @@ id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) { id<2> ItemLimit = Dev.get_info>() * Dev.get_info(); return id<2>{std::min(ItemLimit[0], Height), std::min(ItemLimit[1], Width)}; +} void handler::read_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, bool Block, bool Read) { From 5bb9cd6aa92491d777bb758a1a7c070f01d932ec Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Mon, 13 Feb 2023 07:09:06 -0800 Subject: [PATCH 14/56] created templateless base class for pipes --- .../ext/intel/experimental/host_pipes.hpp | 227 +++++++++++------- .../sycl/ext/intel/experimental/pipes.hpp | 70 +++++- sycl/include/sycl/sycl.hpp | 2 +- sycl/source/CMakeLists.txt | 2 +- sycl/source/detail/host_pipe.cpp | 128 +++++----- sycl/source/detail/pipes.cpp | 27 +++ .../pipes/host_pipe_registration.cpp | 2 +- 7 files changed, 292 insertions(+), 166 deletions(-) create mode 100755 sycl/source/detail/pipes.cpp diff --git a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp index 3d52d2cca8abe..7419ac4d7c5b7 100644 --- a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp @@ -1,93 +1,134 @@ -//==---------------- pipes.hpp - SYCL pipes ------------*- C++ -*-----------==// -// -// 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 -// -// ===--------------------------------------------------------------------=== // - -#pragma once - -#include -#include -#include -#include -#include -#include - -#ifdef XPTI_ENABLE_INSTRUMENTATION -#include -#include -#endif - -namespace sycl { -__SYCL_INLINE_VER_NAMESPACE(_V1) { -namespace ext { -namespace intel { -namespace experimental { - -using default_pipe_properties = - decltype(sycl::ext::oneapi::experimental::properties(min_capacity<0>)); - -template -class -#ifdef __SYCL_DEVICE_ONLY__ - [[__sycl_detail__::add_ir_attributes_global_variable("sycl-host-access", - "readwrite")]] -#endif - // TODO: change name to pipe, and merge into the existing pipe - // implementation - host_pipe { - - struct -// Commented out since the host_pipe attribute is not introduced by the front -// end yet. Confirm with Rob -#ifdef __SYCL_DEVICE_ONLY__ - [[__sycl_detail__::add_ir_attributes_global_variable( - "sycl-host-pipe", - nullptr)]] [[__sycl_detail__:: - host_pipe]] [[__sycl_detail__:: - global_variable_allowed]] // may - // not be - // needed -#endif - __pipeType { - const char __p; - }; - - static constexpr __pipeType __pipe = {0}; - -public: - using value_type = _dataT; - static constexpr int32_t min_cap = - _propertiesT::template has_property() - ? _propertiesT::template get_property().value - : 0; - - static const void *get_host_ptr() { return &__pipe; } - - // Blocking pipes - static _dataT read(queue & q, memory_order order = memory_order::seq_cst); - static void write(queue & q, const _dataT &data, - memory_order order = memory_order::seq_cst); - // Non-blocking pipes - static _dataT read(queue & q, bool &success_code, - memory_order order = memory_order::seq_cst); - static void write(queue & q, const _dataT &data, bool &success_code, - memory_order order = memory_order::seq_cst); - -private: - static constexpr int32_t m_Size = sizeof(_dataT); - static constexpr int32_t m_Alignment = alignof(_dataT); - -#ifdef __SYCL_DEVICE_ONLY__ - static constexpr struct ConstantPipeStorage m_Storage = {m_Size, m_Alignment, - min_cap}; -#endif // __SYCL_DEVICE_ONLY__ -}; - -} // namespace experimental -} // namespace intel -} // namespace ext -} // __SYCL_INLINE_VER_NAMESPACE(_V1) -} // namespace sycl \ No newline at end of file +// //==---------------- pipes.hpp - SYCL pipes ------------*- C++ -*-----------==// +// // +// // 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 +// // +// // ===--------------------------------------------------------------------=== // + +// #pragma once + +// #include +// #include +// #include +// #include +// #include +// #include +// #include + +// #ifdef XPTI_ENABLE_INSTRUMENTATION +// #include +// #include +// #endif + +// namespace sycl { +// __SYCL_INLINE_VER_NAMESPACE(_V1) { +// namespace ext { +// namespace intel { +// namespace experimental { + +// using default_pipe_properties = +// decltype(sycl::ext::oneapi::experimental::properties(min_capacity<0>)); + +// template +// class +// #ifdef __SYCL_DEVICE_ONLY__ +// [[__sycl_detail__::add_ir_attributes_global_variable("sycl-host-access", +// "readwrite")]] +// #endif +// // TODO: change name to pipe, and merge into the existing pipe +// // implementation +// host_pipe : public host_pipe_base{ + +// struct +// // Commented out since the host_pipe attribute is not introduced by the front +// // end yet. Confirm with Rob +// #ifdef __SYCL_DEVICE_ONLY__ +// [[__sycl_detail__::add_ir_attributes_global_variable( +// "sycl-host-pipe", +// nullptr)]] [[__sycl_detail__:: +// host_pipe]] [[__sycl_detail__:: +// global_variable_allowed]] // may +// // not be +// // needed +// #endif +// __pipeType { +// const char __p; +// }; + +// static constexpr __pipeType __pipe = {0}; + +// public: +// using value_type = _dataT; +// static constexpr int32_t min_cap = +// _propertiesT::template has_property() +// ? _propertiesT::template get_property().value +// : 0; + +// static const void *get_host_ptr() { return &__pipe; } + +// std::string get_pipe_name(const void *HostPipePtr){ +// return host_pipe_base::get_pipe_name(HostPipePtr); +// } + +// // Blocking pipes +// static _dataT read(queue & q, memory_order order = memory_order::seq_cst) +// { +// const device Dev = q.get_device(); +// bool IsReadPipeSupported = +// Dev.has_extension("cl_intel_program_scope_host_pipe"); +// if (!IsReadPipeSupported) { +// return &_dataT(); +// } +// _dataT data; +// const void *HostPipePtr = &__pipe; +// const std::string pipe_name = host_pipe_base::get_pipe_name(HostPipePtr); +// event e = q.submit([=](handler &CGH) { +// CGH.read_write_host_pipe(pipe_name, (void *)(&data), sizeof(_dataT), false, +// true /* read */); +// }); +// e.wait(); +// return data; +// } + + +// static void write(queue & q, const _dataT &data, +// memory_order order = memory_order::seq_cst){ +// const device Dev = q.get_device(); +// bool IsReadPipeSupported = +// Dev.has_extension("cl_intel_program_scope_host_pipe"); +// if (!IsReadPipeSupported) { +// return; +// } +// const void *HostPipePtr = &__pipe; +// const std::string pipe_name = host_pipe_base::get_pipe_name(HostPipePtr); +// const void *data_ptr = &data; +// event e = q.submit([=](handler &CGH) { +// CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, +// false /* write */); +// }); +// e.wait(); +// } + + +// // Non-blocking pipes +// static _dataT read(queue & q, bool &success_code, +// memory_order order = memory_order::seq_cst); +// static void write(queue & q, const _dataT &data, bool &success_code, +// memory_order order = memory_order::seq_cst); + +// private: +// static constexpr int32_t m_Size = sizeof(_dataT); +// static constexpr int32_t m_Alignment = alignof(_dataT); + +// #ifdef __SYCL_DEVICE_ONLY__ +// static constexpr struct ConstantPipeStorage m_Storage = {m_Size, m_Alignment, +// min_cap}; +// #endif // __SYCL_DEVICE_ONLY__ +// }; + +// } // namespace experimental +// } // namespace intel +// } // namespace ext +// } // __SYCL_INLINE_VER_NAMESPACE(_V1) +// } // namespace sycl \ No newline at end of file diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index a5660a766385e..5d672a4848726 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -9,16 +9,26 @@ #pragma once #include "fpga_utils.hpp" -#include "pipe_properties.hpp" +#include +#include +#include +#include #include #include #include #include #include +#ifdef XPTI_ENABLE_INSTRUMENTATION +#include +#include +#endif + namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { -namespace ext::intel::experimental { +namespace ext { +namespace intel { +namespace experimental { namespace detail { template @@ -40,10 +50,22 @@ struct ValueOrDefault< }; } // namespace detail +// A helper templateless base class to get the host_pipe name. +class pipe_base{ + + protected: + + pipe_base(); + ~pipe_base(); + + static std::string get_pipe_name(const void *HostPipePtr); + +}; + template -class pipe { +class pipe : public pipe_base{ public: struct #ifdef __SYCL_DEVICE_ONLY__ @@ -171,9 +193,43 @@ class pipe { // Blocking pipes // Host API - static _dataT read(queue & q, memory_order order = memory_order::seq_cst); + static _dataT read(queue & q, memory_order order = memory_order::seq_cst) + { + const device Dev = q.get_device(); + bool IsReadPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsReadPipeSupported) { + return &_dataT(); + } + _dataT data; + const void *HostPipePtr = &m_Storage; + const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, (void *)(&data), sizeof(_dataT), false, + true /* read */); + }); + e.wait(); + return data; + } + static void write(queue & q, const _dataT &data, - memory_order order = memory_order::seq_cst); + memory_order order = memory_order::seq_cst) + { + const device Dev = q.get_device(); + bool IsReadPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsReadPipeSupported) { + return; + } + const void *HostPipePtr = &m_Storage; + const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); + const void *data_ptr = &data; + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, + false /* write */); + }); + e.wait(); +} // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V // friendly LLVM IR. @@ -333,6 +389,8 @@ class pipe { #endif // __SYCL_DEVICE_ONLY__ }; -} // namespace ext::intel::experimental +} // namespace experimental +} // namespace intel +} // namespace ext } // __SYCL_INLINE_VER_NAMESPACE(_V1) } // namespace sycl diff --git a/sycl/include/sycl/sycl.hpp b/sycl/include/sycl/sycl.hpp index 0a64d2cf6b504..dbfb6cff5304a 100644 --- a/sycl/include/sycl/sycl.hpp +++ b/sycl/include/sycl/sycl.hpp @@ -63,7 +63,7 @@ #include #endif #include -#include +#include #include #include #include diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index f31aa09c7328f..e3621f7b0fb8d 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -177,7 +177,6 @@ set(SYCL_SOURCES "detail/global_handler.cpp" "detail/helpers.cpp" "detail/handler_proxy.cpp" - "detail/host_pipe.cpp" "detail/image_accessor_util.cpp" "detail/image_impl.cpp" "detail/jit_compiler.cpp" @@ -185,6 +184,7 @@ set(SYCL_SOURCES "detail/kernel_impl.cpp" "detail/kernel_program_cache.cpp" "detail/memory_manager.cpp" + "detail/pipes.cpp" "detail/platform_impl.cpp" "detail/program_impl.cpp" "detail/program_manager/program_manager.cpp" diff --git a/sycl/source/detail/host_pipe.cpp b/sycl/source/detail/host_pipe.cpp index f62ef794eb797..aefe5df66e801 100644 --- a/sycl/source/detail/host_pipe.cpp +++ b/sycl/source/detail/host_pipe.cpp @@ -1,70 +1,70 @@ -//==-------------------- host_pipe.cpp -----------------------------==// -// -// 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 -// -//===----------------------------------------------------------------------===// +// //==-------------------- host_pipe.cpp -----------------------------==// +// // +// // 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 +// // +// //===----------------------------------------------------------------------===// -#include -#include -#include +// #include +// #include +// #include -namespace sycl { -__SYCL_INLINE_VER_NAMESPACE(_V1) { -namespace ext { -namespace intel { -namespace experimental { +// namespace sycl { +// __SYCL_INLINE_VER_NAMESPACE(_V1) { +// namespace ext { +// namespace intel { +// namespace experimental { -template -_dataT host_pipe<_name, _dataT, _propertiesT>::read(queue &q, - memory_order order) { - const device Dev = q.get_device(); - bool IsReadPipeSupported = - Dev.has_extension("cl_intel_program_scope_host_pipe"); - if (!IsReadPipeSupported) { - return &_dataT(); - } - // TODO: get pipe name from the pipe registration - _dataT data; - const void *HostPipePtr = &__pipe; - detail::HostPipeMapEntry hostPipeEntry = - detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); - const std::string pipe_name = hostPipeEntry.MUniqueId; - event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)(&data), sizeof(_dataT), false, - true /* read */); - }); - e.wait(); - return data; -} +// // template +// // _dataT host_pipe<_name, _dataT, _propertiesT>::read(queue &q, +// // memory_order order) { +// // const device Dev = q.get_device(); +// // bool IsReadPipeSupported = +// // Dev.has_extension("cl_intel_program_scope_host_pipe"); +// // if (!IsReadPipeSupported) { +// // return &_dataT(); +// // } +// // // TODO: get pipe name from the pipe registration +// // _dataT data; +// // const void *HostPipePtr = &__pipe; +// // detail::HostPipeMapEntry hostPipeEntry = +// // detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); +// // const std::string pipe_name = hostPipeEntry.MUniqueId; +// // event e = q.submit([=](handler &CGH) { +// // CGH.read_write_host_pipe(pipe_name, (void *)(&data), sizeof(_dataT), false, +// // true /* read */); +// // }); +// // e.wait(); +// // return data; +// // } -template -void host_pipe<_name, _dataT, _propertiesT>::write(queue &q, const _dataT &data, - memory_order order) { - const device Dev = q.get_device(); - bool IsReadPipeSupported = - Dev.has_extension("cl_intel_program_scope_host_pipe"); - if (!IsReadPipeSupported) { - return; - } - // TODO: get pipe name from the pipe registration - const void *HostPipePtr = &__pipe; - detail::HostPipeMapEntry hostPipeEntry = - detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); - const std::string pipe_name = hostPipeEntry.MUniqueId; - const void *data_ptr = &data; - event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, - false /* write */); - }); - e.wait(); -} +// // template +// // void host_pipe<_name, _dataT, _propertiesT>::write(queue &q, const _dataT &data, +// // memory_order order) { +// // const device Dev = q.get_device(); +// // bool IsReadPipeSupported = +// // Dev.has_extension("cl_intel_program_scope_host_pipe"); +// // if (!IsReadPipeSupported) { +// // return; +// // } +// // // TODO: get pipe name from the pipe registration +// // const void *HostPipePtr = &__pipe; +// // detail::HostPipeMapEntry hostPipeEntry = +// // detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); +// // const std::string pipe_name = hostPipeEntry.MUniqueId; +// // const void *data_ptr = &data; +// // event e = q.submit([=](handler &CGH) { +// // CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, +// // false /* write */); +// // }); +// // e.wait(); +// // } -// TODO: implement non blocking version +// // TODO: implement non blocking version -} // namespace experimental -} // namespace intel -} // namespace ext -} // __SYCL_INLINE_VER_NAMESPACE(_V1) -} // namespace sycl \ No newline at end of file +// } // namespace experimental +// } // namespace intel +// } // namespace ext +// } // __SYCL_INLINE_VER_NAMESPACE(_V1) +// } // namespace sycl \ No newline at end of file diff --git a/sycl/source/detail/pipes.cpp b/sycl/source/detail/pipes.cpp new file mode 100755 index 0000000000000..bbcb79d2c9776 --- /dev/null +++ b/sycl/source/detail/pipes.cpp @@ -0,0 +1,27 @@ +//==-------------------- pipes.cpp -----------------------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { +namespace ext { +namespace intel { +namespace experimental { + +__SYCL_EXPORT std::string pipe_base::get_pipe_name(const void *HostPipePtr){ + return sycl::_V1::detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr)->MUniqueId; + } + +} // namespace experimental +} // namespace intel +} // namespace ext +} // __SYCL_INLINE_VER_NAMESPACE(_V1) +} // namespace sycl \ No newline at end of file diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 0f1a8281ecc3b..fc4bd8b0cf0c3 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -69,7 +69,7 @@ class test_data_type { }; using test_host_pipe = - ext::intel::experimental::host_pipe, test_data_type, pipe_prop>; + ext::intel::experimental::pipe, test_data_type, pipe_prop>; pi_event READ = reinterpret_cast(0); pi_event WRITE = reinterpret_cast(1); From e2c5b86fde8039a1ed7e34ce435c2f15c925f459 Mon Sep 17 00:00:00 2001 From: "Ho, Robert" Date: Mon, 27 Feb 2023 11:10:52 -0800 Subject: [PATCH 15/56] Preliminary implementation of host pipe size property (cherry picked from commit aa48c1fab83a58c4c8714f9d7e12ca00fc72c0ca) --- llvm/include/llvm/SYCLLowerIR/HostPipes.h | 57 +++ llvm/lib/SYCLLowerIR/CMakeLists.txt | 1 + llvm/lib/SYCLLowerIR/HostPipes.cpp | 98 ++++++ llvm/tools/sycl-post-link/sycl-post-link.cpp | 6 + .../sycl/ext/intel/experimental/pipes.hpp | 3 +- sycl/plugins/opencl/pi_opencl.cpp | 2 - .../program_manager/program_manager.cpp | 4 +- sycl/source/detail/scheduler/commands.cpp | 5 +- .../pipes/host_pipe_registration.cpp | 332 +++++++++--------- 9 files changed, 332 insertions(+), 176 deletions(-) create mode 100644 llvm/include/llvm/SYCLLowerIR/HostPipes.h create mode 100644 llvm/lib/SYCLLowerIR/HostPipes.cpp diff --git a/llvm/include/llvm/SYCLLowerIR/HostPipes.h b/llvm/include/llvm/SYCLLowerIR/HostPipes.h new file mode 100644 index 0000000000000..b4cd8ccb82690 --- /dev/null +++ b/llvm/include/llvm/SYCLLowerIR/HostPipes.h @@ -0,0 +1,57 @@ +//===--- HostPipes.h - get required into about SYCL Device Globals ----===// +// +// 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 device global variables and save them as a property set for the +// runtime. +//===----------------------------------------------------------------------===// + +#pragma once + +#include "llvm/ADT/MapVector.h" + +#include +#include + +namespace llvm { + +class GlobalVariable; +class Module; +class StringRef; + +// Represents a device global variable - at SYCL RT level device global +// 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 device global variable. + uint32_t Size; +}; + +using HostPipePropertyMapTy = + MapVector>; + +/// Searches given module for occurrences of device global variable-specific +/// metadata and builds "device global variable name" -> +/// vector<"variable properties"> map. +/// +/// @param M [in] LLVM Module. +/// +/// @returns the "device global variable name" -> vector<"variable properties"> +/// map. +HostPipePropertyMapTy collectHostPipeProperties(const Module &M); + +/// Returns the unique id for the device global variable. +/// +/// @param GV [in] Device Global variable. +/// +/// @returns the unique id of the device global variable represented +/// in the LLVM IR by \c GV. +// StringRef getGlobalVariableUniqueId(const GlobalVariable &GV); + +} // end namespace llvm diff --git a/llvm/lib/SYCLLowerIR/CMakeLists.txt b/llvm/lib/SYCLLowerIR/CMakeLists.txt index b8f6ab50d15b5..3fe3bb06cc69d 100644 --- a/llvm/lib/SYCLLowerIR/CMakeLists.txt +++ b/llvm/lib/SYCLLowerIR/CMakeLists.txt @@ -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 diff --git a/llvm/lib/SYCLLowerIR/HostPipes.cpp b/llvm/lib/SYCLLowerIR/HostPipes.cpp new file mode 100644 index 0000000000000..341e00d8d9059 --- /dev/null +++ b/llvm/lib/SYCLLowerIR/HostPipes.cpp @@ -0,0 +1,98 @@ +//===----- HostPipes.cpp - SYCL Device Globals 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/DeviceGlobals.h" +#include "llvm/SYCLLowerIR/HostPipes.h" +#include "llvm/SYCLLowerIR/CompileTimePropertiesPass.h" + +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/IR/Module.h" + +#include + +using namespace llvm; + +namespace { + +constexpr StringRef SYCL_HOST_PIPE_SIZE_ATTR = "sycl-host-pipe-size"; +constexpr StringRef SYCL_UNIQUE_ID_ATTR = "sycl-unique-id"; + +/// Returns the size (in bytes) of the underlying 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 getUnderlyingTypeSize(const GlobalVariable &GV) { + assert(GV.hasAttribute(SYCL_HOST_PIPE_SIZE_ATTR) && + "The device global variable must have the 'sycl-host-pipe-size' " + "attribute that must contain a number representing the size of the " + "underlying type T of the device global variable"); + return getAttributeAsInteger(GV, SYCL_HOST_PIPE_SIZE_ATTR); +} + +} // anonymous namespace + +namespace llvm { + +/// Return \c true if the variable @GV is a device global variable. +/// +/// The function checks whether the variable has the LLVM IR attribute \c +/// sycl-host-pipe-size. +/// @param GV [in] A variable to test. +/// +/// @return \c true if the variable is a device global variable, \c false +/// otherwise. +bool isHostPipeVariable(const GlobalVariable &GV) { + return GV.hasAttribute(SYCL_HOST_PIPE_SIZE_ATTR); +} + +#if 0 +/// Returns the unique id for the device global variable. +/// +/// The function gets this value from the LLVM IR attribute \c +/// sycl-unique-id. +/// +/// @param GV [in] Device Global variable. +/// +/// @returns the unique id of the device global 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"); + return GV.getAttribute(SYCL_UNIQUE_ID_ATTR).getValueAsString(); +} +#endif + +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)] = { getUnderlyingTypeSize(GV) }; + } + + return HPM; +} + +} // namespace llvm diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index f9110752bc331..13468c241da0a 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -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" @@ -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); diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 5d672a4848726..89e076bb01645 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -70,7 +70,8 @@ class pipe : public pipe_base{ struct #ifdef __SYCL_DEVICE_ONLY__ [[__sycl_detail__::add_ir_attributes_global_variable( - "sycl-host-pipe", nullptr)]][[__sycl_detail__::sycl_type(host_pipe)]] + "sycl-host-pipe", "sycl-host-pipe-size", nullptr, sizeof(_dataT))]] + [[__sycl_detail__::sycl_type(host_pipe)]] #endif // __SYCL_DEVICE_ONLY___ ConstantPipeStorageExp #ifdef __SYCL_DEVICE_ONLY__ diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index ce7b9f9116085..2977eb6f86301 100644 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -1714,7 +1714,6 @@ pi_result piextEnqueueReadHostPipe(pi_queue queue, pi_program program, blocking, ptr, size, num_events_in_waitlist, cast(events_waitlist), cast(event))); } - return RetVal; } @@ -1743,7 +1742,6 @@ pi_result piextEnqueueWriteHostPipe(pi_queue queue, pi_program program, blocking, ptr, size, num_events_in_waitlist, cast(events_waitlist), cast(event))); } - return RetVal; } diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index eff8f548811fe..8c0e9bad14eb7 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1672,9 +1672,7 @@ std::vector ProgramManager::getDeviceGlobalEntries( void ProgramManager::addOrInitHostPipeEntry(const void *HostPipePtr, const char *UniqueId) { std::lock_guard HostPipesGuard(m_HostPipesMutex); - - assert(m_HostPipes.find(UniqueId) == m_HostPipes.end() && - "Host pipe has already been registered."); + auto ExistingHostPipe = m_HostPipes.find(UniqueId); if (ExistingHostPipe != m_HostPipes.end()) { ExistingHostPipe->second->initialize(HostPipePtr); diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index a06540fc742b9..b90e544517ca6 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -2336,12 +2336,9 @@ pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, void *ptr, size_t size, std::vector &RawEvents, RT::PiEvent *OutEvent, bool read) { - // TODO: Few options of getting the kernel name / program object: - // 1. Encode this in the pipe registration - // 2. Initialize the pipe registration from first kernel launch, but then this - // will violate the spec detail::HostPipeMapEntry *hostPipeEntry = ProgramManager::getInstance().getHostPipeEntry(PipeName); + RT::PiProgram Program = ProgramManager::getInstance().createPIProgram( *(hostPipeEntry->mDeviceImage), Queue->get_context(), Queue->get_device()); diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index fc4bd8b0cf0c3..7259f349d40b1 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -1,166 +1,166 @@ -//==-------------- host_pipe_registration.cpp - Host pipe tests------------==// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include -#include - -#include -#include -#include - -template class TestKernel; - -namespace sycl { -__SYCL_INLINE_VER_NAMESPACE(_V1) { -namespace detail { -template struct KernelInfo> { - static constexpr unsigned getNumParams() { return 0; } - static const kernel_param_desc_t &getParamDesc(int) { - static kernel_param_desc_t Dummy; - return Dummy; - } - static constexpr const char *getName() { return "TestKernel"; } - static constexpr bool isESIMD() { return false; } - static constexpr bool callsThisItem() { return false; } - static constexpr bool callsAnyThisFreeFunction() { return false; } - static constexpr int64_t getKernelSize() { return KernelSize; } -}; - -} // namespace detail -} // __SYCL_INLINE_VER_NAMESPACE(_V1) -} // namespace sycl - -static sycl::unittest::PiImage generateDefaultImage() { - using namespace sycl::unittest; - - PiPropertySet PropSet; - - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - - PiArray Entries = makeEmptyKernels({"TestKernel"}); - - PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; - - return Img; -} - -using namespace sycl; -using pipe_prop = decltype(ext::oneapi::experimental::properties( - ext::intel::experimental::min_capacity<5>)); - -template struct pipe_id { - static constexpr unsigned id = ID; -}; - -class test_data_type { -public: - int num; -}; - -using test_host_pipe = - ext::intel::experimental::pipe, test_data_type, pipe_prop>; - -pi_event READ = reinterpret_cast(0); -pi_event WRITE = reinterpret_cast(1); -static constexpr test_data_type PipeReadVal = {8}; -static test_data_type PipeWriteVal = {0}; -pi_result redefinedEnqueueReadHostPipe(pi_queue, pi_program, const char *, - pi_bool, void *ptr, size_t, pi_uint32, - const pi_event *, pi_event *event) { - *(((test_data_type *)ptr)) = PipeReadVal; - *event = READ; - return PI_SUCCESS; -} -pi_result redefinedEnqueueWriteHostPipe(pi_queue, pi_program, const char *, - pi_bool, void *ptr, size_t, pi_uint32, - const pi_event *, pi_event *event) { - test_data_type tmp = {9}; - PipeWriteVal = tmp; - *event = WRITE; - return PI_SUCCESS; -} - -void preparePiMock(unittest::PiMock &Mock) { - Mock.redefine( - redefinedEnqueueReadHostPipe); - Mock.redefine( - redefinedEnqueueWriteHostPipe); -} - -class PipeTest : public ::testing::Test { -public: - PipeTest() : Mock{}, Plt{Mock.getPlatform()} {} - -protected: - void SetUp() override { - std::clog << "Zibai started the setup()\n"; - preparePiMock(Mock); - const sycl::device Dev = Plt.get_devices()[0]; - sycl::context Ctx{Dev}; - sycl::queue Q{Ctx, Dev}; - ctx = Ctx; - q = Q; - } - -protected: - unittest::PiMock Mock; - sycl::platform Plt; - context ctx; - queue q; -}; - -TEST_F(PipeTest, Basic) { - - // Fake registration of host pipes - sycl::detail::host_pipe_map::add(test_host_pipe::get_host_ptr(), - "test_host_pipe_unique_id"); - - // Device registration - std::clog << "Zibai started the Device registration\n"; - static sycl::unittest::PiImage Img = generateDefaultImage(); - static sycl::unittest::PiImageArray<1> ImgArray{&Img}; - - std::clog << "Zibai started the get_host_ptr\n"; - const void *HostPipePtr = test_host_pipe::get_host_ptr(); - std::clog << "Zibai started the hostPipeEntry\n"; - detail::HostPipeMapEntry *hostPipeEntry = - detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); - const std::string pipe_name = hostPipeEntry->MUniqueId; - std::clog << "Zibai what is the pipe_name " << pipe_name - << "\n"; // this part is fine - test_data_type host_pipe_read_data = {}; - void *data_ptr = &host_pipe_read_data; - std::clog << "Zibai started the q submit for read\n"; - event e = q.submit([&](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, - true /* read */); - // CGH.single_task>([&]() {}); - }); - - std::clog << "Zibai started the wait for read\n"; - e.wait(); - std::clog << "Zibai started the assert\n"; - // auto host_pipe_read_data = test_host_pipe::read(q); - assert(host_pipe_read_data.num == PipeReadVal.num); - test_data_type tmp = {9}; - data_ptr = &tmp; - std::clog << "Zibai started the q submit for write\n"; - event e_write = q.submit([&](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, - false /* write */); - }); - e_write.wait(); - // test_host_pipe::write(q, tmp); - assert(PipeWriteVal.num == 9); -} \ No newline at end of file +// //==-------------- host_pipe_registration.cpp - Host pipe tests------------==// +// // +// // 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 +// // +// //===----------------------------------------------------------------------===// + +// #include +// #include + +// #include +// #include +// #include + +// template class TestKernel; + +// namespace sycl { +// __SYCL_INLINE_VER_NAMESPACE(_V1) { +// namespace detail { +// template struct KernelInfo> { +// static constexpr unsigned getNumParams() { return 0; } +// static const kernel_param_desc_t &getParamDesc(int) { +// static kernel_param_desc_t Dummy; +// return Dummy; +// } +// static constexpr const char *getName() { return "TestKernel"; } +// static constexpr bool isESIMD() { return false; } +// static constexpr bool callsThisItem() { return false; } +// static constexpr bool callsAnyThisFreeFunction() { return false; } +// static constexpr int64_t getKernelSize() { return KernelSize; } +// }; + +// } // namespace detail +// } // __SYCL_INLINE_VER_NAMESPACE(_V1) +// } // namespace sycl + +// static sycl::unittest::PiImage generateDefaultImage() { +// using namespace sycl::unittest; + +// PiPropertySet PropSet; + +// std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data + +// PiArray Entries = makeEmptyKernels({"TestKernel"}); + +// PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format +// __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec +// "", // Compile options +// "", // Link options +// std::move(Bin), +// std::move(Entries), +// std::move(PropSet)}; + +// return Img; +// } + +// using namespace sycl; +// using pipe_prop = decltype(ext::oneapi::experimental::properties( +// ext::intel::experimental::min_capacity<5>)); + +// template struct pipe_id { +// static constexpr unsigned id = ID; +// }; + +// class test_data_type { +// public: +// int num; +// }; + +// using test_host_pipe = +// ext::intel::experimental::pipe, test_data_type, pipe_prop>; + +// pi_event READ = reinterpret_cast(0); +// pi_event WRITE = reinterpret_cast(1); +// static constexpr test_data_type PipeReadVal = {8}; +// static test_data_type PipeWriteVal = {0}; +// pi_result redefinedEnqueueReadHostPipe(pi_queue, pi_program, const char *, +// pi_bool, void *ptr, size_t, pi_uint32, +// const pi_event *, pi_event *event) { +// *(((test_data_type *)ptr)) = PipeReadVal; +// *event = READ; +// return PI_SUCCESS; +// } +// pi_result redefinedEnqueueWriteHostPipe(pi_queue, pi_program, const char *, +// pi_bool, void *ptr, size_t, pi_uint32, +// const pi_event *, pi_event *event) { +// test_data_type tmp = {9}; +// PipeWriteVal = tmp; +// *event = WRITE; +// return PI_SUCCESS; +// } + +// void preparePiMock(unittest::PiMock &Mock) { +// Mock.redefine( +// redefinedEnqueueReadHostPipe); +// Mock.redefine( +// redefinedEnqueueWriteHostPipe); +// } + +// class PipeTest : public ::testing::Test { +// public: +// PipeTest() : Mock{}, Plt{Mock.getPlatform()} {} + +// protected: +// void SetUp() override { +// std::clog << "Zibai started the setup()\n"; +// preparePiMock(Mock); +// const sycl::device Dev = Plt.get_devices()[0]; +// sycl::context Ctx{Dev}; +// sycl::queue Q{Ctx, Dev}; +// ctx = Ctx; +// q = Q; +// } + +// protected: +// unittest::PiMock Mock; +// sycl::platform Plt; +// context ctx; +// queue q; +// }; + +// TEST_F(PipeTest, Basic) { + +// // Fake registration of host pipes +// sycl::detail::host_pipe_map::add(test_host_pipe::get_host_ptr(), +// "test_host_pipe_unique_id"); + +// // Device registration +// std::clog << "Zibai started the Device registration\n"; +// static sycl::unittest::PiImage Img = generateDefaultImage(); +// static sycl::unittest::PiImageArray<1> ImgArray{&Img}; + +// std::clog << "Zibai started the get_host_ptr\n"; +// const void *HostPipePtr = test_host_pipe::get_host_ptr(); +// std::clog << "Zibai started the hostPipeEntry\n"; +// detail::HostPipeMapEntry *hostPipeEntry = +// detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); +// const std::string pipe_name = hostPipeEntry->MUniqueId; +// std::clog << "Zibai what is the pipe_name " << pipe_name +// << "\n"; // this part is fine +// test_data_type host_pipe_read_data = {}; +// void *data_ptr = &host_pipe_read_data; +// std::clog << "Zibai started the q submit for read\n"; +// event e = q.submit([&](handler &CGH) { +// CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, +// true /* read */); +// // CGH.single_task>([&]() {}); +// }); + +// std::clog << "Zibai started the wait for read\n"; +// e.wait(); +// std::clog << "Zibai started the assert\n"; +// // auto host_pipe_read_data = test_host_pipe::read(q); +// assert(host_pipe_read_data.num == PipeReadVal.num); +// test_data_type tmp = {9}; +// data_ptr = &tmp; +// std::clog << "Zibai started the q submit for write\n"; +// event e_write = q.submit([&](handler &CGH) { +// CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, +// false /* write */); +// }); +// e_write.wait(); +// // test_host_pipe::write(q, tmp); +// assert(PipeWriteVal.num == 9); +// } \ No newline at end of file From c43b3c13ed7dbdaf0edc4e6ca4622772b1c13bba Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Mon, 6 Mar 2023 06:29:46 -0800 Subject: [PATCH 16/56] fix blocking read and add API for nonblocking read&write --- buildbot/dependency.py | 4 +- .../sycl/ext/intel/experimental/pipes.hpp | 112 ++++++++++++++---- sycl/include/sycl/handler.hpp | 10 -- sycl/source/detail/handler_impl.hpp | 13 ++ .../program_manager/program_manager.cpp | 2 +- sycl/source/detail/scheduler/commands.cpp | 3 +- sycl/source/handler.cpp | 16 ++- 7 files changed, 114 insertions(+), 46 deletions(-) diff --git a/buildbot/dependency.py b/buildbot/dependency.py index e14388d49ef9e..0e07fe14a5e8c 100644 --- a/buildbot/dependency.py +++ b/buildbot/dependency.py @@ -50,7 +50,7 @@ def do_dependency(args): ocl_header_dir = os.path.join(args.obj_dir, "OpenCL-Headers") if not os.path.isdir(ocl_header_dir): clone_cmd = ["git", "clone", "https://github.com/zibaiwan/OpenCL-Headers", - "OpenCL-Headers", "-b", "host-pipe"] # TODO: Remove change once upstream header changed + "OpenCL-Headers", "-b", "host-pipe-final"] # TODO: Remove change once upstream header changed subprocess.check_call(clone_cmd, cwd=args.obj_dir) else: fetch_cmd = ["git", "pull", "--ff", "--ff-only", "origin"] @@ -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", "35c1b8458b9118c68ddde2b0961509583ba4c1d8"] # TODO: Remove change once upstream header changed + checkout_cmd = ["git", "checkout", "5a71a821072b80926b6b0c6083a6ad3cf78ffa19"] # TODO: Remove change once upstream header changed subprocess.check_call(checkout_cmd, cwd=ocl_header_dir) # fetch and build OpenCL ICD loader diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 89e076bb01645..efc4661a52b79 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -89,9 +89,74 @@ class pipe : public pipe_base{ // Host API static _dataT read(queue & q, bool &success_code, - memory_order order = memory_order::seq_cst); + memory_order order = memory_order::seq_cst) + { + std::cout << "Zibai pipes.hpp non-blocking read is being called \n"; + const device Dev = q.get_device(); + bool IsPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsPipeSupported) { + std::cout << "Zibai pipes.hpp read is being called not supported 2\n"; + return _dataT(); + } + _dataT data; + void *data_ptr = &data; + const void *HostPipePtr = &m_Storage; + const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); + + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), false, + true /* read */); + }); + e.wait(); // Zibai double check, I think wait() is still needed even it's non-blocking? + // Note: below code is making assumption that the negative open event value (failing) will be propagated to SYCL runtime, and not return complete if fail + if (e.get_info() == sycl::info::event_command_status::complete) { + success_code = true; + return *(_dataT *)data_ptr; + }else{ + success_code = false; + return _dataT(); + } + } + static void write(queue & q, const _dataT &data, bool &success_code, - memory_order order = memory_order::seq_cst); + memory_order order = memory_order::seq_cst) + { + const device Dev = q.get_device(); + bool IsPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsPipeSupported) { + std::cout << "Zibai pipes.hpp write is being called not supported\n"; + return; + } + + const void *HostPipePtr = &m_Storage; + const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); + const void *data_ptr = &data; + + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, + false /* write */); + }); + e.wait(); // Zibai double check, I think wait() is still needed even it's non-blocking? + // Note: below code is making assumption that the negative open event value (failing) will be propagated to SYCL runtime, and not return complete if fail + // If it always return complete, need to figure out how to propagate the error back. + // https://intel.github.io/llvm-docs/doxygen/namespacesycl_1_1__V1_1_1info.html#a614308c11885e0d8171d1ce5480bcbb0ad9a22d7a8178d5b42a8750123cbfe5b1 + // event_command_status::ext_oneapi_unknown = -1, hopefully this -1 is returned. + // In pi.h, PI_EVENT_COMPLETE is 0 + // typedef enum { + // PI_EVENT_COMPLETE = 0x0, + // PI_EVENT_RUNNING = 0x1, + // PI_EVENT_SUBMITTED = 0x2, + // PI_EVENT_QUEUED = 0x3 + // } _pi_event_status; + // Question: why pi_event status has no failure? + if (e.get_info() == sycl::info::event_command_status::complete) { + success_code = true; + }else{ + success_code = false; + } +} // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V // friendly LLVM IR. @@ -196,40 +261,41 @@ class pipe : public pipe_base{ // Host API static _dataT read(queue & q, memory_order order = memory_order::seq_cst) { - const device Dev = q.get_device(); - bool IsReadPipeSupported = + const device Dev = q.get_device(); + bool IsPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); - if (!IsReadPipeSupported) { + if (!IsPipeSupported) { return &_dataT(); } _dataT data; + void *data_ptr = &data; const void *HostPipePtr = &m_Storage; const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)(&data), sizeof(_dataT), false, - true /* read */); + CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), true, + true /*blocking read */); }); e.wait(); - return data; + return *(_dataT *)data_ptr; } static void write(queue & q, const _dataT &data, memory_order order = memory_order::seq_cst) { - const device Dev = q.get_device(); - bool IsReadPipeSupported = - Dev.has_extension("cl_intel_program_scope_host_pipe"); - if (!IsReadPipeSupported) { - return; - } - const void *HostPipePtr = &m_Storage; - const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); - const void *data_ptr = &data; - event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, - false /* write */); - }); - e.wait(); + const device Dev = q.get_device(); + bool IsPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsPipeSupported) { + return; + } + const void *HostPipePtr = &m_Storage; + const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); + const void *data_ptr = &data; + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), true, + false /*blocking write */); + }); + e.wait(); } // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V @@ -332,7 +398,7 @@ class pipe : public pipe_base{ static constexpr int32_t m_ready_latency = detail::ValueOrDefault<_propertiesT, ready_latency_key>::template get(0); static constexpr int32_t m_bits_per_symbol = detail::ValueOrDefault<_propertiesT, bits_per_symbol_key>::template get(0); - static constexpr bool m_uses_valid = detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get(0); + static constexpr bool m_uses_valid = detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get(true); static constexpr bool m_first_symbol_in_high_order_bits = detail::ValueOrDefault<_propertiesT, first_symbol_in_high_order_bits_key>::template get(0); static constexpr protocol_name m_protocol = detail::ValueOrDefault<_propertiesT, protocol_key>::template get(protocol_name::AVALON_STREAMING); diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 8ec443448a76c..99091516fa376 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -2789,16 +2789,6 @@ class __SYCL_EXPORT handler { /// The list of valid SYCL events that need to complete /// before barrier command can be executed std::vector MEventsWaitWithBarrier; - /// Pipe name that uniquely identifies a pipe. - std::string HostPipeName; - /// Pipe host pointer, the address of its constexpr __pipe member. - void *HostPipePtr = nullptr; - /// Host pipe read write operation is blocking. - bool HostPipeBlocking = false; - /// The size of returned type for each read. - size_t HostPipeTypeSize = 0; - /// If the pipe operation is read or write, 1 for read 0 for write. - bool HostPipeRead = true; bool MIsHost = false; diff --git a/sycl/source/detail/handler_impl.hpp b/sycl/source/detail/handler_impl.hpp index e697452b06666..8067ac0524796 100644 --- a/sycl/source/detail/handler_impl.hpp +++ b/sycl/source/detail/handler_impl.hpp @@ -84,6 +84,19 @@ class handler_impl { /// Boolean flag for whether the device_global had the device_image_scope /// property. bool MIsDeviceImageScoped = false; + + // Program scope pipe information. + + // Pipe name that uniquely identifies a pipe. + std::string HostPipeName; + // Pipe host pointer, the address of its constexpr __pipe member. + void *HostPipePtr = nullptr; + // Host pipe read write operation is blocking. + bool HostPipeBlocking = false; + // The size of returned type for each read. + size_t HostPipeTypeSize = 0; + // If the pipe operation is read or write, 1 for read 0 for write. + bool HostPipeRead = true; }; } // namespace detail diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 8c0e9bad14eb7..445d6b0ad5b71 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1177,7 +1177,7 @@ bool ProgramManager::kernelUsesAssert(OSModuleHandle M, void ProgramManager::addImages(pi_device_binaries DeviceBinary) { std::lock_guard Guard(Sync::getGlobalLock()); const bool DumpImages = std::getenv("SYCL_DUMP_IMAGES") && !m_UseSpvFile; - + std::cout << "Zibai debug program_manager->addImages is called 1 \n "; for (int I = 0; I < DeviceBinary->NumDeviceBinaries; I++) { pi_device_binary RawImg = &(DeviceBinary->DeviceBinaries[I]); OSModuleHandle M = OSUtil::getOSModuleHandle(RawImg); diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index b90e544517ca6..f440df9576e78 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -2361,6 +2361,7 @@ pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, RawEvents.size(), RawEvents.empty() ? nullptr : &RawEvents[0], OutEvent); } + std::cout << "Zibai debug enqueueReadWriteHostPipe, ptr address is " << ptr << "\n"; return Error; } @@ -2784,7 +2785,7 @@ pi_int32 ExecCGCommand::enqueueImp() { if (!Event) { Event = &MEvent->getHandleRef(); } - + std::cout << "ReadWriteHostPipe hostPtr address is " << hostPtr << "\n"; return enqueueReadWriteHostPipe(MQueue, pipeName, blocking, hostPtr, typeSize, RawEvents, Event, read); } diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 960382fc0cecc..9ef10ec1bfafd 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -359,8 +359,8 @@ event handler::finalize() { } case detail::CG::ReadWriteHostPipe: { CommandGroup.reset(new detail::CGReadWriteHostPipe( - HostPipeName, HostPipeBlocking, HostPipePtr, HostPipeTypeSize, - HostPipeRead, std::move(MArgsStorage), std::move(MAccStorage), + MImpl->HostPipeName, MImpl->HostPipeBlocking, MImpl->HostPipePtr, MImpl->HostPipeTypeSize, + MImpl->HostPipeRead, std::move(MArgsStorage), std::move(MAccStorage), std::move(MSharedPtrStorage), std::move(MRequirements), std::move(MEvents), MCodeLoc)); break; @@ -863,13 +863,11 @@ id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) { void handler::read_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, bool Block, bool Read) { - // throwIfActionIsCreated(); // Need this?? Zibai - std::clog << "Zibai remove this read_write_host_pipe is invoked \n"; - HostPipeName = Name; - HostPipePtr = Ptr; - HostPipeTypeSize = Size; - HostPipeBlocking = Block; - HostPipeRead = Read; + MImpl->HostPipeName = Name; + MImpl->HostPipePtr = Ptr; + MImpl->HostPipeTypeSize = Size; + MImpl->HostPipeBlocking = Block; + MImpl->HostPipeRead = Read; setType(detail::CG::ReadWriteHostPipe); } From 714d25d2aae922d9a568f9c0f5254f9d1e375818 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Mon, 13 Mar 2023 09:22:29 -0700 Subject: [PATCH 17/56] fixup --- sycl/plugins/opencl/pi_opencl.cpp | 6 +-- .../pipes/host_pipe_registration.cpp | 42 +++++++------------ 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index 2977eb6f86301..f2896c2bf4914 100644 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -72,8 +72,8 @@ CONSTFIX char clEnqueueWriteGlobalVariableName[] = CONSTFIX char clEnqueueReadGlobalVariableName[] = "clEnqueueReadGlobalVariableINTEL"; // Names of host pipe functions queried from OpenCL -CONSTFIX char clEnqueueReadHostPipeName[] = "clEnqueueReadHostPipeIntelFPGA"; -CONSTFIX char clEnqueueWriteHostPipeName[] = "clEnqueueWriteHostPipeIntelFPGA"; +CONSTFIX char clEnqueueReadHostPipeName[] = "clEnqueueReadHostPipeINTEL"; +CONSTFIX char clEnqueueWriteHostPipeName[] = "clEnqueueWriteHostPipeINTEL"; #undef CONSTFIX @@ -1730,12 +1730,10 @@ pi_result piextEnqueueWriteHostPipe(pi_queue queue, pi_program program, if (CLErr != CL_SUCCESS) { return cast(CLErr); } - clEnqueueWriteHostPipeIntelFPGA_fn FuncPtr = nullptr; pi_result RetVal = getExtFuncFromContext( cast(CLContext), &FuncPtr); - if (FuncPtr) { RetVal = cast(FuncPtr( cast(queue), cast(program), pipe_symbol, diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 7259f349d40b1..5da60fc579f17 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -56,25 +56,15 @@ // } // using namespace sycl; -// using pipe_prop = decltype(ext::oneapi::experimental::properties( -// ext::intel::experimental::min_capacity<5>)); +// using default_pipe_properties = decltype(sycl::ext::oneapi::experimental::properties(sycl::ext::intel::experimental::uses_valid)); -// template struct pipe_id { -// static constexpr unsigned id = ID; -// }; - -// class test_data_type { -// public: -// int num; -// }; - -// using test_host_pipe = -// ext::intel::experimental::pipe, test_data_type, pipe_prop>; +// class PipeID; +// using Pipe = sycl::ext::intel::experimental::pipe; // pi_event READ = reinterpret_cast(0); // pi_event WRITE = reinterpret_cast(1); -// static constexpr test_data_type PipeReadVal = {8}; -// static test_data_type PipeWriteVal = {0}; +// static constexpr int PipeReadVal = 8; +// static int PipeWriteVal = 0; // pi_result redefinedEnqueueReadHostPipe(pi_queue, pi_program, const char *, // pi_bool, void *ptr, size_t, pi_uint32, // const pi_event *, pi_event *event) { @@ -85,8 +75,7 @@ // pi_result redefinedEnqueueWriteHostPipe(pi_queue, pi_program, const char *, // pi_bool, void *ptr, size_t, pi_uint32, // const pi_event *, pi_event *event) { -// test_data_type tmp = {9}; -// PipeWriteVal = tmp; +// PipeWriteVal = 9; // *event = WRITE; // return PI_SUCCESS; // } @@ -123,7 +112,7 @@ // TEST_F(PipeTest, Basic) { // // Fake registration of host pipes -// sycl::detail::host_pipe_map::add(test_host_pipe::get_host_ptr(), +// sycl::detail::host_pipe_map::add(Pipe::get_host_ptr(), // "test_host_pipe_unique_id"); // // Device registration @@ -132,35 +121,32 @@ // static sycl::unittest::PiImageArray<1> ImgArray{&Img}; // std::clog << "Zibai started the get_host_ptr\n"; -// const void *HostPipePtr = test_host_pipe::get_host_ptr(); +// const void *HostPipePtr = Pipe::get_host_ptr(); // std::clog << "Zibai started the hostPipeEntry\n"; // detail::HostPipeMapEntry *hostPipeEntry = // detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); // const std::string pipe_name = hostPipeEntry->MUniqueId; // std::clog << "Zibai what is the pipe_name " << pipe_name // << "\n"; // this part is fine -// test_data_type host_pipe_read_data = {}; +// int host_pipe_read_data; // void *data_ptr = &host_pipe_read_data; // std::clog << "Zibai started the q submit for read\n"; // event e = q.submit([&](handler &CGH) { -// CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, +// CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), false, // true /* read */); -// // CGH.single_task>([&]() {}); // }); // std::clog << "Zibai started the wait for read\n"; // e.wait(); // std::clog << "Zibai started the assert\n"; -// // auto host_pipe_read_data = test_host_pipe::read(q); -// assert(host_pipe_read_data.num == PipeReadVal.num); -// test_data_type tmp = {9}; +// assert(host_pipe_read_data == PipeReadVal); +// int tmp = {9}; // data_ptr = &tmp; // std::clog << "Zibai started the q submit for write\n"; // event e_write = q.submit([&](handler &CGH) { -// CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(test_data_type), false, +// CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), false, // false /* write */); // }); // e_write.wait(); -// // test_host_pipe::write(q, tmp); -// assert(PipeWriteVal.num == 9); +// assert(PipeWriteVal == 9); // } \ No newline at end of file From a1d422a5364357244d8ce09b791e26a18c86c890 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 14 Mar 2023 08:49:30 -0700 Subject: [PATCH 18/56] fixup --- buildbot/dependency.py | 2 +- opencl/CMakeLists.txt | 2 +- .../sycl/ext/intel/experimental/pipes.hpp | 2 + .../program_manager/program_manager.cpp | 5 +- sycl/source/detail/scheduler/commands.cpp | 6 +- .../pipes/host_pipe_registration.cpp | 317 +++++++++--------- 6 files changed, 176 insertions(+), 158 deletions(-) diff --git a/buildbot/dependency.py b/buildbot/dependency.py index 0e07fe14a5e8c..cfd3361cb2470 100644 --- a/buildbot/dependency.py +++ b/buildbot/dependency.py @@ -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", "5a71a821072b80926b6b0c6083a6ad3cf78ffa19"] # TODO: Remove change once upstream header changed + checkout_cmd = ["git", "checkout", "d57c0d85426703e3edd366a018a6e7385d534eb3"] # TODO: Remove change once upstream header changed subprocess.check_call(checkout_cmd, cwd=ocl_header_dir) # fetch and build OpenCL ICD loader diff --git a/opencl/CMakeLists.txt b/opencl/CMakeLists.txt index 32732ec9a09aa..e377b2c19e2bc 100644 --- a/opencl/CMakeLists.txt +++ b/opencl/CMakeLists.txt @@ -20,7 +20,7 @@ set(OCL_LOADER_REPO # Repo tags/hashes -set(OCL_HEADERS_TAG 35c1b8458b9118c68ddde2b0961509583ba4c1d8) #TODO: Change it back once the official header is in. +set(OCL_HEADERS_TAG d57c0d85426703e3edd366a018a6e7385d534eb3) #TODO: Change it back once the official header is in. set(OCL_LOADER_TAG 9a3e962f16f5097d2054233ad8b6dad51b6f41b7) # OpenCL Headers diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index efc4661a52b79..b39f94d1a7c39 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -256,6 +256,8 @@ class pipe : public pipe_base{ write(Data, Success, oneapi::experimental::properties{}); } + static const void *get_host_ptr() { return &m_Storage; } + // Blocking pipes // Host API diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 445d6b0ad5b71..cc0e11c284ebd 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1177,7 +1177,7 @@ bool ProgramManager::kernelUsesAssert(OSModuleHandle M, void ProgramManager::addImages(pi_device_binaries DeviceBinary) { std::lock_guard Guard(Sync::getGlobalLock()); const bool DumpImages = std::getenv("SYCL_DUMP_IMAGES") && !m_UseSpvFile; - std::cout << "Zibai debug program_manager->addImages is called 1 \n "; + std::clog << "Zibai debug program_manager->addImages is called 1 \n "; for (int I = 0; I < DeviceBinary->NumDeviceBinaries; I++) { pi_device_binary RawImg = &(DeviceBinary->DeviceBinaries[I]); OSModuleHandle M = OSUtil::getOSModuleHandle(RawImg); @@ -1315,9 +1315,10 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) { // ... and initialize associated host_pipe information { std::lock_guard HostPipesGuard(m_HostPipesMutex); - + std::clog << "Zibai debug program_manager->adding hostpipe info is called 2 \n "; auto HostPipes = Img->getHostPipes(); for (const pi_device_binary_property &HostPipe : HostPipes) { + std::clog << "Zibai debug program_manager->adding hostpipe info is called, any hostpipe exist? \n "; ByteArray HostPipeInfo = DeviceBinaryProperty(HostPipe).asByteArray(); // The supplied host_pipe info property is expected to contain: diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index f440df9576e78..af1d720ec4bc4 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -2339,6 +2339,10 @@ pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, detail::HostPipeMapEntry *hostPipeEntry = ProgramManager::getInstance().getHostPipeEntry(PipeName); + if (hostPipeEntry->mDeviceImage == NULL){ + std::clog << "Zibai debug enqueueReadWriteHostPipe is called, warning hostPipeEntry->mDeviceImage is NULL \n"; + } + RT::PiProgram Program = ProgramManager::getInstance().createPIProgram( *(hostPipeEntry->mDeviceImage), Queue->get_context(), Queue->get_device()); @@ -2361,7 +2365,6 @@ pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, RawEvents.size(), RawEvents.empty() ? nullptr : &RawEvents[0], OutEvent); } - std::cout << "Zibai debug enqueueReadWriteHostPipe, ptr address is " << ptr << "\n"; return Error; } @@ -2785,7 +2788,6 @@ pi_int32 ExecCGCommand::enqueueImp() { if (!Event) { Event = &MEvent->getHandleRef(); } - std::cout << "ReadWriteHostPipe hostPtr address is " << hostPtr << "\n"; return enqueueReadWriteHostPipe(MQueue, pipeName, blocking, hostPtr, typeSize, RawEvents, Event, read); } diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 5da60fc579f17..0d4e31ffc27a3 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -1,152 +1,165 @@ -// //==-------------- host_pipe_registration.cpp - Host pipe tests------------==// -// // -// // 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 -// // -// //===----------------------------------------------------------------------===// - -// #include -// #include - -// #include -// #include -// #include - -// template class TestKernel; - -// namespace sycl { -// __SYCL_INLINE_VER_NAMESPACE(_V1) { -// namespace detail { -// template struct KernelInfo> { -// static constexpr unsigned getNumParams() { return 0; } -// static const kernel_param_desc_t &getParamDesc(int) { -// static kernel_param_desc_t Dummy; -// return Dummy; -// } -// static constexpr const char *getName() { return "TestKernel"; } -// static constexpr bool isESIMD() { return false; } -// static constexpr bool callsThisItem() { return false; } -// static constexpr bool callsAnyThisFreeFunction() { return false; } -// static constexpr int64_t getKernelSize() { return KernelSize; } -// }; - -// } // namespace detail -// } // __SYCL_INLINE_VER_NAMESPACE(_V1) -// } // namespace sycl - -// static sycl::unittest::PiImage generateDefaultImage() { -// using namespace sycl::unittest; - -// PiPropertySet PropSet; - -// std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - -// PiArray Entries = makeEmptyKernels({"TestKernel"}); - -// PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format -// __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec -// "", // Compile options -// "", // Link options -// std::move(Bin), -// std::move(Entries), -// std::move(PropSet)}; - -// return Img; -// } - -// using namespace sycl; -// using default_pipe_properties = decltype(sycl::ext::oneapi::experimental::properties(sycl::ext::intel::experimental::uses_valid)); - -// class PipeID; -// using Pipe = sycl::ext::intel::experimental::pipe; - -// pi_event READ = reinterpret_cast(0); -// pi_event WRITE = reinterpret_cast(1); -// static constexpr int PipeReadVal = 8; -// static int PipeWriteVal = 0; -// pi_result redefinedEnqueueReadHostPipe(pi_queue, pi_program, const char *, -// pi_bool, void *ptr, size_t, pi_uint32, -// const pi_event *, pi_event *event) { -// *(((test_data_type *)ptr)) = PipeReadVal; -// *event = READ; -// return PI_SUCCESS; -// } -// pi_result redefinedEnqueueWriteHostPipe(pi_queue, pi_program, const char *, -// pi_bool, void *ptr, size_t, pi_uint32, -// const pi_event *, pi_event *event) { -// PipeWriteVal = 9; -// *event = WRITE; -// return PI_SUCCESS; -// } - -// void preparePiMock(unittest::PiMock &Mock) { -// Mock.redefine( -// redefinedEnqueueReadHostPipe); -// Mock.redefine( -// redefinedEnqueueWriteHostPipe); -// } - -// class PipeTest : public ::testing::Test { -// public: -// PipeTest() : Mock{}, Plt{Mock.getPlatform()} {} - -// protected: -// void SetUp() override { -// std::clog << "Zibai started the setup()\n"; -// preparePiMock(Mock); -// const sycl::device Dev = Plt.get_devices()[0]; -// sycl::context Ctx{Dev}; -// sycl::queue Q{Ctx, Dev}; -// ctx = Ctx; -// q = Q; -// } - -// protected: -// unittest::PiMock Mock; -// sycl::platform Plt; -// context ctx; -// queue q; -// }; - -// TEST_F(PipeTest, Basic) { - -// // Fake registration of host pipes -// sycl::detail::host_pipe_map::add(Pipe::get_host_ptr(), -// "test_host_pipe_unique_id"); - -// // Device registration -// std::clog << "Zibai started the Device registration\n"; -// static sycl::unittest::PiImage Img = generateDefaultImage(); -// static sycl::unittest::PiImageArray<1> ImgArray{&Img}; - -// std::clog << "Zibai started the get_host_ptr\n"; -// const void *HostPipePtr = Pipe::get_host_ptr(); -// std::clog << "Zibai started the hostPipeEntry\n"; -// detail::HostPipeMapEntry *hostPipeEntry = -// detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); -// const std::string pipe_name = hostPipeEntry->MUniqueId; -// std::clog << "Zibai what is the pipe_name " << pipe_name -// << "\n"; // this part is fine -// int host_pipe_read_data; -// void *data_ptr = &host_pipe_read_data; -// std::clog << "Zibai started the q submit for read\n"; -// event e = q.submit([&](handler &CGH) { -// CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), false, -// true /* read */); -// }); - -// std::clog << "Zibai started the wait for read\n"; -// e.wait(); -// std::clog << "Zibai started the assert\n"; -// assert(host_pipe_read_data == PipeReadVal); -// int tmp = {9}; -// data_ptr = &tmp; -// std::clog << "Zibai started the q submit for write\n"; -// event e_write = q.submit([&](handler &CGH) { -// CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), false, -// false /* write */); -// }); -// e_write.wait(); -// assert(PipeWriteVal == 9); -// } \ No newline at end of file +//==-------------- host_pipe_registration.cpp - Host pipe tests------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include +#include +#include +#include +#include +#include + +template class TestKernel; + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { +namespace detail { +template struct KernelInfo> { + static constexpr unsigned getNumParams() { return 0; } + static const kernel_param_desc_t &getParamDesc(int) { + static kernel_param_desc_t Dummy; + return Dummy; + } + static constexpr const char *getName() { return "TestKernel"; } + static constexpr bool isESIMD() { return false; } + static constexpr bool callsThisItem() { return false; } + static constexpr bool callsAnyThisFreeFunction() { return false; } + static constexpr int64_t getKernelSize() { return KernelSize; } +}; + +} // namespace detail +} // __SYCL_INLINE_VER_NAMESPACE(_V1) +} // namespace sycl + +static sycl::unittest::PiImage generateDefaultImage() { + using namespace sycl::unittest; + + PiPropertySet PropSet; + + std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data + + PiArray Entries = makeEmptyKernels({"TestKernel"}); + + PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format + __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec + "", // Compile options + "", // Link options + std::move(Bin), + std::move(Entries), + std::move(PropSet)}; + + return Img; +} + +using namespace sycl; +using default_pipe_properties = decltype(sycl::ext::oneapi::experimental::properties(sycl::ext::intel::experimental::uses_valid)); + +class PipeID; +using Pipe = sycl::ext::intel::experimental::pipe; + +pi_event READ = reinterpret_cast(0); +pi_event WRITE = reinterpret_cast(1); +static constexpr int PipeReadVal = 8; +static int PipeWriteVal = 0; +pi_result redefinedEnqueueReadHostPipe(pi_queue, pi_program, const char *, + pi_bool, void *ptr, size_t, pi_uint32, + const pi_event *, pi_event *event) { + *(((int *)ptr)) = PipeReadVal; + *event = READ; + return PI_SUCCESS; +} +pi_result redefinedEnqueueWriteHostPipe(pi_queue, pi_program, const char *, + pi_bool, void *ptr, size_t, pi_uint32, + const pi_event *, pi_event *event) { + PipeWriteVal = 9; + *event = WRITE; + return PI_SUCCESS; +} + +void preparePiMock(unittest::PiMock &Mock) { + Mock.redefine( + redefinedEnqueueReadHostPipe); + Mock.redefine( + redefinedEnqueueWriteHostPipe); +} + +class PipeTest : public ::testing::Test { +public: + PipeTest() : Mock{}, Plt{Mock.getPlatform()} {} + +protected: + void SetUp() override { + std::clog << "Zibai started the setup()\n"; + preparePiMock(Mock); + const sycl::device Dev = Plt.get_devices()[0]; + sycl::context Ctx{Dev}; + sycl::queue Q{Ctx, Dev}; + ctx = Ctx; + q = Q; + } + +protected: + unittest::PiMock Mock; + sycl::platform Plt; + context ctx; + queue q; +}; + +TEST_F(PipeTest, Basic) { + + // Fake registration of host pipes + sycl::detail::host_pipe_map::add(Pipe::get_host_ptr(), + "test_host_pipe_unique_id"); + + // Device registration + std::clog << "Zibai started the Device registration\n"; + static sycl::unittest::PiImage Img = generateDefaultImage(); + static sycl::unittest::PiImageArray<1> ImgArray{&Img}; + + std::clog << "Zibai started the get_host_ptr\n"; + const void *HostPipePtr = Pipe::get_host_ptr(); + std::clog << "Zibai started the hostPipeEntry\n"; + detail::HostPipeMapEntry *hostPipeEntry = + detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); + + if (hostPipeEntry->mDeviceImage == NULL){ + std::clog << "Zibai debug: hostPipeEntry->mDeviceImage is NULL \n"; + } + pi_device_binary_struct pi_device_binary = Img.convertToNativeType(); + hostPipeEntry->initialize((detail::RTDeviceBinaryImage *)&pi_device_binary); + + if (hostPipeEntry->mDeviceImage != NULL){ + std::clog << "Zibai debug: hostPipeEntry->mDeviceImage is not NULL anymore \n"; + } + + const std::string pipe_name = hostPipeEntry->MUniqueId; + std::clog << "Zibai what is the pipe_name " << pipe_name + << "\n"; // this part is fine + int host_pipe_read_data; + void *data_ptr = &host_pipe_read_data; + std::clog << "Zibai started the q submit for read\n"; + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), true, + true /* read */); + }); + std::clog << "Zibai started the wait for read\n"; + e.wait(); + std::clog << "Zibai started the assert\n"; + assert(host_pipe_read_data == PipeReadVal); + int tmp = {9}; + data_ptr = &tmp; + std::clog << "Zibai started the q submit for write\n"; + event e_write = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), true, + false /* write */); + }); + e_write.wait(); + assert(PipeWriteVal == 9); +} \ No newline at end of file From a3034643cac731e6dd3fa759b7cc31f23d057026 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 14 Mar 2023 10:43:38 -0700 Subject: [PATCH 19/56] fixup --- .../ext/intel/experimental/host_pipes.hpp | 134 ------------------ .../sycl/ext/intel/experimental/pipes.hpp | 20 +-- sycl/source/detail/host_pipe.cpp | 70 --------- .../program_manager/program_manager.cpp | 3 - sycl/source/detail/scheduler/commands.cpp | 4 - sycl/unittests/pipes/CMakeLists.txt | 2 +- .../pipes/host_pipe_registration.cpp | 18 +-- 7 files changed, 4 insertions(+), 247 deletions(-) delete mode 100644 sycl/include/sycl/ext/intel/experimental/host_pipes.hpp delete mode 100644 sycl/source/detail/host_pipe.cpp diff --git a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp b/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp deleted file mode 100644 index 7419ac4d7c5b7..0000000000000 --- a/sycl/include/sycl/ext/intel/experimental/host_pipes.hpp +++ /dev/null @@ -1,134 +0,0 @@ -// //==---------------- pipes.hpp - SYCL pipes ------------*- C++ -*-----------==// -// // -// // 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 -// // -// // ===--------------------------------------------------------------------=== // - -// #pragma once - -// #include -// #include -// #include -// #include -// #include -// #include -// #include - -// #ifdef XPTI_ENABLE_INSTRUMENTATION -// #include -// #include -// #endif - -// namespace sycl { -// __SYCL_INLINE_VER_NAMESPACE(_V1) { -// namespace ext { -// namespace intel { -// namespace experimental { - -// using default_pipe_properties = -// decltype(sycl::ext::oneapi::experimental::properties(min_capacity<0>)); - -// template -// class -// #ifdef __SYCL_DEVICE_ONLY__ -// [[__sycl_detail__::add_ir_attributes_global_variable("sycl-host-access", -// "readwrite")]] -// #endif -// // TODO: change name to pipe, and merge into the existing pipe -// // implementation -// host_pipe : public host_pipe_base{ - -// struct -// // Commented out since the host_pipe attribute is not introduced by the front -// // end yet. Confirm with Rob -// #ifdef __SYCL_DEVICE_ONLY__ -// [[__sycl_detail__::add_ir_attributes_global_variable( -// "sycl-host-pipe", -// nullptr)]] [[__sycl_detail__:: -// host_pipe]] [[__sycl_detail__:: -// global_variable_allowed]] // may -// // not be -// // needed -// #endif -// __pipeType { -// const char __p; -// }; - -// static constexpr __pipeType __pipe = {0}; - -// public: -// using value_type = _dataT; -// static constexpr int32_t min_cap = -// _propertiesT::template has_property() -// ? _propertiesT::template get_property().value -// : 0; - -// static const void *get_host_ptr() { return &__pipe; } - -// std::string get_pipe_name(const void *HostPipePtr){ -// return host_pipe_base::get_pipe_name(HostPipePtr); -// } - -// // Blocking pipes -// static _dataT read(queue & q, memory_order order = memory_order::seq_cst) -// { -// const device Dev = q.get_device(); -// bool IsReadPipeSupported = -// Dev.has_extension("cl_intel_program_scope_host_pipe"); -// if (!IsReadPipeSupported) { -// return &_dataT(); -// } -// _dataT data; -// const void *HostPipePtr = &__pipe; -// const std::string pipe_name = host_pipe_base::get_pipe_name(HostPipePtr); -// event e = q.submit([=](handler &CGH) { -// CGH.read_write_host_pipe(pipe_name, (void *)(&data), sizeof(_dataT), false, -// true /* read */); -// }); -// e.wait(); -// return data; -// } - - -// static void write(queue & q, const _dataT &data, -// memory_order order = memory_order::seq_cst){ -// const device Dev = q.get_device(); -// bool IsReadPipeSupported = -// Dev.has_extension("cl_intel_program_scope_host_pipe"); -// if (!IsReadPipeSupported) { -// return; -// } -// const void *HostPipePtr = &__pipe; -// const std::string pipe_name = host_pipe_base::get_pipe_name(HostPipePtr); -// const void *data_ptr = &data; -// event e = q.submit([=](handler &CGH) { -// CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, -// false /* write */); -// }); -// e.wait(); -// } - - -// // Non-blocking pipes -// static _dataT read(queue & q, bool &success_code, -// memory_order order = memory_order::seq_cst); -// static void write(queue & q, const _dataT &data, bool &success_code, -// memory_order order = memory_order::seq_cst); - -// private: -// static constexpr int32_t m_Size = sizeof(_dataT); -// static constexpr int32_t m_Alignment = alignof(_dataT); - -// #ifdef __SYCL_DEVICE_ONLY__ -// static constexpr struct ConstantPipeStorage m_Storage = {m_Size, m_Alignment, -// min_cap}; -// #endif // __SYCL_DEVICE_ONLY__ -// }; - -// } // namespace experimental -// } // namespace intel -// } // namespace ext -// } // __SYCL_INLINE_VER_NAMESPACE(_V1) -// } // namespace sycl \ No newline at end of file diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index b39f94d1a7c39..b03a761e123be 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -91,12 +91,10 @@ class pipe : public pipe_base{ static _dataT read(queue & q, bool &success_code, memory_order order = memory_order::seq_cst) { - std::cout << "Zibai pipes.hpp non-blocking read is being called \n"; const device Dev = q.get_device(); bool IsPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); if (!IsPipeSupported) { - std::cout << "Zibai pipes.hpp read is being called not supported 2\n"; return _dataT(); } _dataT data; @@ -108,8 +106,7 @@ class pipe : public pipe_base{ CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), false, true /* read */); }); - e.wait(); // Zibai double check, I think wait() is still needed even it's non-blocking? - // Note: below code is making assumption that the negative open event value (failing) will be propagated to SYCL runtime, and not return complete if fail + e.wait(); if (e.get_info() == sycl::info::event_command_status::complete) { success_code = true; return *(_dataT *)data_ptr; @@ -126,7 +123,6 @@ class pipe : public pipe_base{ bool IsPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); if (!IsPipeSupported) { - std::cout << "Zibai pipes.hpp write is being called not supported\n"; return; } @@ -138,19 +134,7 @@ class pipe : public pipe_base{ CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, false /* write */); }); - e.wait(); // Zibai double check, I think wait() is still needed even it's non-blocking? - // Note: below code is making assumption that the negative open event value (failing) will be propagated to SYCL runtime, and not return complete if fail - // If it always return complete, need to figure out how to propagate the error back. - // https://intel.github.io/llvm-docs/doxygen/namespacesycl_1_1__V1_1_1info.html#a614308c11885e0d8171d1ce5480bcbb0ad9a22d7a8178d5b42a8750123cbfe5b1 - // event_command_status::ext_oneapi_unknown = -1, hopefully this -1 is returned. - // In pi.h, PI_EVENT_COMPLETE is 0 - // typedef enum { - // PI_EVENT_COMPLETE = 0x0, - // PI_EVENT_RUNNING = 0x1, - // PI_EVENT_SUBMITTED = 0x2, - // PI_EVENT_QUEUED = 0x3 - // } _pi_event_status; - // Question: why pi_event status has no failure? + e.wait(); if (e.get_info() == sycl::info::event_command_status::complete) { success_code = true; }else{ diff --git a/sycl/source/detail/host_pipe.cpp b/sycl/source/detail/host_pipe.cpp deleted file mode 100644 index aefe5df66e801..0000000000000 --- a/sycl/source/detail/host_pipe.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// //==-------------------- host_pipe.cpp -----------------------------==// -// // -// // 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 -// // -// //===----------------------------------------------------------------------===// - -// #include -// #include -// #include - -// namespace sycl { -// __SYCL_INLINE_VER_NAMESPACE(_V1) { -// namespace ext { -// namespace intel { -// namespace experimental { - -// // template -// // _dataT host_pipe<_name, _dataT, _propertiesT>::read(queue &q, -// // memory_order order) { -// // const device Dev = q.get_device(); -// // bool IsReadPipeSupported = -// // Dev.has_extension("cl_intel_program_scope_host_pipe"); -// // if (!IsReadPipeSupported) { -// // return &_dataT(); -// // } -// // // TODO: get pipe name from the pipe registration -// // _dataT data; -// // const void *HostPipePtr = &__pipe; -// // detail::HostPipeMapEntry hostPipeEntry = -// // detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); -// // const std::string pipe_name = hostPipeEntry.MUniqueId; -// // event e = q.submit([=](handler &CGH) { -// // CGH.read_write_host_pipe(pipe_name, (void *)(&data), sizeof(_dataT), false, -// // true /* read */); -// // }); -// // e.wait(); -// // return data; -// // } - -// // template -// // void host_pipe<_name, _dataT, _propertiesT>::write(queue &q, const _dataT &data, -// // memory_order order) { -// // const device Dev = q.get_device(); -// // bool IsReadPipeSupported = -// // Dev.has_extension("cl_intel_program_scope_host_pipe"); -// // if (!IsReadPipeSupported) { -// // return; -// // } -// // // TODO: get pipe name from the pipe registration -// // const void *HostPipePtr = &__pipe; -// // detail::HostPipeMapEntry hostPipeEntry = -// // detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); -// // const std::string pipe_name = hostPipeEntry.MUniqueId; -// // const void *data_ptr = &data; -// // event e = q.submit([=](handler &CGH) { -// // CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, -// // false /* write */); -// // }); -// // e.wait(); -// // } - -// // TODO: implement non blocking version - -// } // namespace experimental -// } // namespace intel -// } // namespace ext -// } // __SYCL_INLINE_VER_NAMESPACE(_V1) -// } // namespace sycl \ No newline at end of file diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index cc0e11c284ebd..35073e36e7a5c 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1177,7 +1177,6 @@ bool ProgramManager::kernelUsesAssert(OSModuleHandle M, void ProgramManager::addImages(pi_device_binaries DeviceBinary) { std::lock_guard Guard(Sync::getGlobalLock()); const bool DumpImages = std::getenv("SYCL_DUMP_IMAGES") && !m_UseSpvFile; - std::clog << "Zibai debug program_manager->addImages is called 1 \n "; for (int I = 0; I < DeviceBinary->NumDeviceBinaries; I++) { pi_device_binary RawImg = &(DeviceBinary->DeviceBinaries[I]); OSModuleHandle M = OSUtil::getOSModuleHandle(RawImg); @@ -1315,10 +1314,8 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) { // ... and initialize associated host_pipe information { std::lock_guard HostPipesGuard(m_HostPipesMutex); - std::clog << "Zibai debug program_manager->adding hostpipe info is called 2 \n "; auto HostPipes = Img->getHostPipes(); for (const pi_device_binary_property &HostPipe : HostPipes) { - std::clog << "Zibai debug program_manager->adding hostpipe info is called, any hostpipe exist? \n "; ByteArray HostPipeInfo = DeviceBinaryProperty(HostPipe).asByteArray(); // The supplied host_pipe info property is expected to contain: diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index af1d720ec4bc4..a438450e29b8b 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -2339,10 +2339,6 @@ pi_int32 enqueueReadWriteHostPipe(const QueueImplPtr &Queue, detail::HostPipeMapEntry *hostPipeEntry = ProgramManager::getInstance().getHostPipeEntry(PipeName); - if (hostPipeEntry->mDeviceImage == NULL){ - std::clog << "Zibai debug enqueueReadWriteHostPipe is called, warning hostPipeEntry->mDeviceImage is NULL \n"; - } - RT::PiProgram Program = ProgramManager::getInstance().createPIProgram( *(hostPipeEntry->mDeviceImage), Queue->get_context(), Queue->get_device()); diff --git a/sycl/unittests/pipes/CMakeLists.txt b/sycl/unittests/pipes/CMakeLists.txt index 9bec8a94609c1..58069920f5cb4 100644 --- a/sycl/unittests/pipes/CMakeLists.txt +++ b/sycl/unittests/pipes/CMakeLists.txt @@ -5,4 +5,4 @@ add_sycl_unittest(PipeTests OBJECT ) add_dependencies(PipeTests sycl) -target_include_directories(PipeTests PRIVATE SYSTEM ${sycl_inc_dir}) \ No newline at end of file +target_include_directories(PipeTests PRIVATE SYSTEM ${sycl_inc_dir}) diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 0d4e31ffc27a3..c780b1a7d7d92 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -96,7 +96,6 @@ class PipeTest : public ::testing::Test { protected: void SetUp() override { - std::clog << "Zibai started the setup()\n"; preparePiMock(Mock); const sycl::device Dev = Plt.get_devices()[0]; sycl::context Ctx{Dev}; @@ -119,43 +118,28 @@ TEST_F(PipeTest, Basic) { "test_host_pipe_unique_id"); // Device registration - std::clog << "Zibai started the Device registration\n"; static sycl::unittest::PiImage Img = generateDefaultImage(); static sycl::unittest::PiImageArray<1> ImgArray{&Img}; - std::clog << "Zibai started the get_host_ptr\n"; const void *HostPipePtr = Pipe::get_host_ptr(); - std::clog << "Zibai started the hostPipeEntry\n"; detail::HostPipeMapEntry *hostPipeEntry = detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); - if (hostPipeEntry->mDeviceImage == NULL){ - std::clog << "Zibai debug: hostPipeEntry->mDeviceImage is NULL \n"; - } pi_device_binary_struct pi_device_binary = Img.convertToNativeType(); hostPipeEntry->initialize((detail::RTDeviceBinaryImage *)&pi_device_binary); - if (hostPipeEntry->mDeviceImage != NULL){ - std::clog << "Zibai debug: hostPipeEntry->mDeviceImage is not NULL anymore \n"; - } - const std::string pipe_name = hostPipeEntry->MUniqueId; - std::clog << "Zibai what is the pipe_name " << pipe_name - << "\n"; // this part is fine + int host_pipe_read_data; void *data_ptr = &host_pipe_read_data; - std::clog << "Zibai started the q submit for read\n"; event e = q.submit([=](handler &CGH) { CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), true, true /* read */); }); - std::clog << "Zibai started the wait for read\n"; e.wait(); - std::clog << "Zibai started the assert\n"; assert(host_pipe_read_data == PipeReadVal); int tmp = {9}; data_ptr = &tmp; - std::clog << "Zibai started the q submit for write\n"; event e_write = q.submit([=](handler &CGH) { CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), true, false /* write */); From 104e2347760120cffdeaf864f4bc9dc5833f0988 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 14 Mar 2023 11:17:57 -0700 Subject: [PATCH 20/56] fixup --- sycl/include/sycl/ext/intel/experimental/pipes.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index b03a761e123be..0ccb918c13324 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -251,7 +251,7 @@ class pipe : public pipe_base{ bool IsPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); if (!IsPipeSupported) { - return &_dataT(); + return _dataT(); } _dataT data; void *data_ptr = &data; From 3d164e87f2824d0a780dfc1e4aabd4d3368fddf5 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 15 Mar 2023 06:58:32 -0700 Subject: [PATCH 21/56] clang format fixup --- llvm/lib/SYCLLowerIR/HostPipes.cpp | 4 +- sycl/include/sycl/detail/cg.hpp | 1 - .../intel/experimental/pipe_properties.hpp | 18 +- .../sycl/ext/intel/experimental/pipes.hpp | 210 +++++++++--------- sycl/include/sycl/sycl.hpp | 2 +- sycl/plugins/level_zero/pi_level_zero.cpp | 1 - sycl/source/detail/handler_impl.hpp | 2 +- sycl/source/detail/pipes.cpp | 8 +- .../program_manager/program_manager.cpp | 3 +- sycl/source/handler.cpp | 8 +- .../pipes/host_pipe_registration.cpp | 13 +- 11 files changed, 143 insertions(+), 127 deletions(-) diff --git a/llvm/lib/SYCLLowerIR/HostPipes.cpp b/llvm/lib/SYCLLowerIR/HostPipes.cpp index 341e00d8d9059..8b258962b14fc 100644 --- a/llvm/lib/SYCLLowerIR/HostPipes.cpp +++ b/llvm/lib/SYCLLowerIR/HostPipes.cpp @@ -8,9 +8,9 @@ // See comments in the header. //===----------------------------------------------------------------------===// -#include "llvm/SYCLLowerIR/DeviceGlobals.h" #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" @@ -89,7 +89,7 @@ HostPipePropertyMapTy collectHostPipeProperties(const Module &M) { if (!isHostPipeVariable(GV)) continue; - HPM[getGlobalVariableUniqueId(GV)] = { getUnderlyingTypeSize(GV) }; + HPM[getGlobalVariableUniqueId(GV)] = {getUnderlyingTypeSize(GV)}; } return HPM; diff --git a/sycl/include/sycl/detail/cg.hpp b/sycl/include/sycl/detail/cg.hpp index e83c4a21c9220..c09420ff33c4d 100644 --- a/sycl/include/sycl/detail/cg.hpp +++ b/sycl/include/sycl/detail/cg.hpp @@ -491,7 +491,6 @@ class CGMemset2DUSM : public CG { size_t getWidth() const { return MWidth; } size_t getHeight() const { return MHeight; } char getValue() const { return MValue; } - }; /// "ReadWriteHostPipe" command group class. diff --git a/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp index 226a14212aee2..747c6359c7012 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipe_properties.hpp @@ -58,11 +58,12 @@ struct first_symbol_in_high_order_bits_key { std::bool_constant>; }; -enum class protocol_name : std::uint16_t { +enum class protocol_name : std::uint16_t { AVALON_STREAMING = 0, AVALON_STREAMING_USES_READY = 1, AVALON_MM = 2, - AVALON_MM_USES_READY = 3 }; + AVALON_MM_USES_READY = 3 +}; struct protocol_key { template @@ -98,10 +99,15 @@ inline constexpr first_symbol_in_high_order_bits_key::value_t template inline constexpr protocol_key::value_t protocol; -inline constexpr protocol_key::value_t protocol_avalon_streaming; -inline constexpr protocol_key::value_t protocol_avalon_streaming_uses_ready; -inline constexpr protocol_key::value_t protocol_avalon_mm; -inline constexpr protocol_key::value_t protocol_avalon_mm_uses_ready; +inline constexpr protocol_key::value_t + protocol_avalon_streaming; +inline constexpr protocol_key::value_t< + protocol_name::AVALON_STREAMING_USES_READY> + protocol_avalon_streaming_uses_ready; +inline constexpr protocol_key::value_t + protocol_avalon_mm; +inline constexpr protocol_key::value_t + protocol_avalon_mm_uses_ready; } // namespace experimental } // namespace intel diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 0ccb918c13324..f497762f8dd22 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -9,13 +9,13 @@ #pragma once #include "fpga_utils.hpp" -#include -#include -#include -#include #include #include +#include +#include +#include #include +#include #include #include @@ -51,31 +51,29 @@ struct ValueOrDefault< } // namespace detail // A helper templateless base class to get the host_pipe name. -class pipe_base{ - - protected: - - pipe_base(); - ~pipe_base(); +class pipe_base { - static std::string get_pipe_name(const void *HostPipePtr); +protected: + pipe_base(); + ~pipe_base(); + static std::string get_pipe_name(const void *HostPipePtr); }; template -class pipe : public pipe_base{ +class pipe : public pipe_base { public: - struct + struct #ifdef __SYCL_DEVICE_ONLY__ - [[__sycl_detail__::add_ir_attributes_global_variable( - "sycl-host-pipe", "sycl-host-pipe-size", nullptr, sizeof(_dataT))]] - [[__sycl_detail__::sycl_type(host_pipe)]] + [[__sycl_detail__::add_ir_attributes_global_variable( + "sycl-host-pipe", "sycl-host-pipe-size", nullptr, + sizeof(_dataT))]] [[__sycl_detail__::sycl_type(host_pipe)]] #endif // __SYCL_DEVICE_ONLY___ - ConstantPipeStorageExp + ConstantPipeStorageExp #ifdef __SYCL_DEVICE_ONLY__ - : ConstantPipeStorage + : ConstantPipeStorage #endif // __SYCL_DEVICE_ONLY___ { int32_t _ReadyLatency; @@ -88,59 +86,59 @@ class pipe : public pipe_base{ // Non-blocking pipes // Host API - static _dataT read(queue & q, bool &success_code, - memory_order order = memory_order::seq_cst) - { - const device Dev = q.get_device(); - bool IsPipeSupported = - Dev.has_extension("cl_intel_program_scope_host_pipe"); - if (!IsPipeSupported) { - return _dataT(); - } - _dataT data; - void *data_ptr = &data; - const void *HostPipePtr = &m_Storage; - const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); - - event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), false, - true /* read */); - }); - e.wait(); - if (e.get_info() == sycl::info::event_command_status::complete) { - success_code = true; - return *(_dataT *)data_ptr; - }else{ - success_code = false; - return _dataT(); - } - } + static _dataT read(queue &q, bool &success_code, + memory_order order = memory_order::seq_cst) { + const device Dev = q.get_device(); + bool IsPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsPipeSupported) { + return _dataT(); + } + _dataT data; + void *data_ptr = &data; + const void *HostPipePtr = &m_Storage; + const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); - static void write(queue & q, const _dataT &data, bool &success_code, - memory_order order = memory_order::seq_cst) - { - const device Dev = q.get_device(); - bool IsPipeSupported = - Dev.has_extension("cl_intel_program_scope_host_pipe"); - if (!IsPipeSupported) { - return; + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), false, + true /* read */); + }); + e.wait(); + if (e.get_info() == + sycl::info::event_command_status::complete) { + success_code = true; + return *(_dataT *)data_ptr; + } else { + success_code = false; + return _dataT(); + } } - const void *HostPipePtr = &m_Storage; - const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); - const void *data_ptr = &data; + static void write(queue &q, const _dataT &data, bool &success_code, + memory_order order = memory_order::seq_cst) { + const device Dev = q.get_device(); + bool IsPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsPipeSupported) { + return; + } + + const void *HostPipePtr = &m_Storage; + const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); + const void *data_ptr = &data; - event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, - false /* write */); - }); - e.wait(); - if (e.get_info() == sycl::info::event_command_status::complete) { + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), + false, false /* write */); + }); + e.wait(); + if (e.get_info() == + sycl::info::event_command_status::complete) { success_code = true; - }else{ - success_code = false; + } else { + success_code = false; + } } -} // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V // friendly LLVM IR. @@ -245,29 +243,27 @@ class pipe : public pipe_base{ // Blocking pipes // Host API - static _dataT read(queue & q, memory_order order = memory_order::seq_cst) - { - const device Dev = q.get_device(); - bool IsPipeSupported = - Dev.has_extension("cl_intel_program_scope_host_pipe"); - if (!IsPipeSupported) { - return _dataT(); - } - _dataT data; - void *data_ptr = &data; - const void *HostPipePtr = &m_Storage; - const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); - event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), true, - true /*blocking read */); - }); - e.wait(); - return *(_dataT *)data_ptr; + static _dataT read(queue &q, memory_order order = memory_order::seq_cst) { + const device Dev = q.get_device(); + bool IsPipeSupported = + Dev.has_extension("cl_intel_program_scope_host_pipe"); + if (!IsPipeSupported) { + return _dataT(); + } + _dataT data; + void *data_ptr = &data; + const void *HostPipePtr = &m_Storage; + const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); + event e = q.submit([=](handler &CGH) { + CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), true, + true /*blocking read */); + }); + e.wait(); + return *(_dataT *)data_ptr; } - static void write(queue & q, const _dataT &data, - memory_order order = memory_order::seq_cst) - { + static void write(queue &q, const _dataT &data, + memory_order order = memory_order::seq_cst) { const device Dev = q.get_device(); bool IsPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); @@ -278,12 +274,12 @@ class pipe : public pipe_base{ const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); const void *data_ptr = &data; event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), true, - false /*blocking write */); + CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), + true, false /*blocking write */); }); e.wait(); -} - + } + // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V // friendly LLVM IR. template @@ -382,21 +378,33 @@ class pipe : public pipe_base{ static constexpr int32_t m_Alignment = alignof(_dataT); static constexpr int32_t m_Capacity = _min_capacity; - static constexpr int32_t m_ready_latency = detail::ValueOrDefault<_propertiesT, ready_latency_key>::template get(0); - static constexpr int32_t m_bits_per_symbol = detail::ValueOrDefault<_propertiesT, bits_per_symbol_key>::template get(0); - static constexpr bool m_uses_valid = detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get(true); - static constexpr bool m_first_symbol_in_high_order_bits = detail::ValueOrDefault<_propertiesT, first_symbol_in_high_order_bits_key>::template get(0); - static constexpr protocol_name m_protocol = detail::ValueOrDefault<_propertiesT, protocol_key>::template get(protocol_name::AVALON_STREAMING); + static constexpr int32_t m_ready_latency = + detail::ValueOrDefault<_propertiesT, + ready_latency_key>::template get(0); + static constexpr int32_t m_bits_per_symbol = + detail::ValueOrDefault<_propertiesT, + bits_per_symbol_key>::template get(0); + static constexpr bool m_uses_valid = + detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get( + true); + static constexpr bool m_first_symbol_in_high_order_bits = + detail::ValueOrDefault< + _propertiesT, + first_symbol_in_high_order_bits_key>::template get(0); + static constexpr protocol_name m_protocol = + detail::ValueOrDefault<_propertiesT, protocol_key>::template get< + protocol_name>(protocol_name::AVALON_STREAMING); public: - static constexpr struct ConstantPipeStorageExp m_Storage = { + static constexpr struct ConstantPipeStorageExp m_Storage = { #ifdef __SYCL_DEVICE_ONLY__ - { m_Size, m_Alignment, m_Capacity }, + {m_Size, m_Alignment, m_Capacity}, #endif // __SYCL_DEVICE_ONLY___ - m_ready_latency, - m_bits_per_symbol, m_uses_valid, - m_first_symbol_in_high_order_bits, - m_protocol }; + m_ready_latency, + m_bits_per_symbol, + m_uses_valid, + m_first_symbol_in_high_order_bits, + m_protocol}; #ifdef __SYCL_DEVICE_ONLY__ private: diff --git a/sycl/include/sycl/sycl.hpp b/sycl/include/sycl/sycl.hpp index dbfb6cff5304a..ab07d7fb9dbb7 100644 --- a/sycl/include/sycl/sycl.hpp +++ b/sycl/include/sycl/sycl.hpp @@ -63,8 +63,8 @@ #include #endif #include -#include #include +#include #include #include #include diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 22c5bfe946036..8ec380a9df3cd 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -7933,7 +7933,6 @@ pi_result piextEnqueueDeviceGlobalVariableRead( PI_COMMAND_TYPE_DEVICE_GLOBAL_VARIABLE_READ, Queue, Dst, BlockingRead, Count, pi_cast(GlobalVarPtr) + Offset, NumEventsInWaitList, EventsWaitList, Event, PreferCopyEngine); - } /// API for Read from host pipe. /// diff --git a/sycl/source/detail/handler_impl.hpp b/sycl/source/detail/handler_impl.hpp index 8067ac0524796..b9c8de9db345c 100644 --- a/sycl/source/detail/handler_impl.hpp +++ b/sycl/source/detail/handler_impl.hpp @@ -86,7 +86,7 @@ class handler_impl { bool MIsDeviceImageScoped = false; // Program scope pipe information. - + // Pipe name that uniquely identifies a pipe. std::string HostPipeName; // Pipe host pointer, the address of its constexpr __pipe member. diff --git a/sycl/source/detail/pipes.cpp b/sycl/source/detail/pipes.cpp index bbcb79d2c9776..a3b156a85a0a8 100755 --- a/sycl/source/detail/pipes.cpp +++ b/sycl/source/detail/pipes.cpp @@ -16,9 +16,11 @@ namespace ext { namespace intel { namespace experimental { -__SYCL_EXPORT std::string pipe_base::get_pipe_name(const void *HostPipePtr){ - return sycl::_V1::detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr)->MUniqueId; - } +__SYCL_EXPORT std::string pipe_base::get_pipe_name(const void *HostPipePtr) { + return sycl::_V1::detail::ProgramManager::getInstance() + .getHostPipeEntry(HostPipePtr) + ->MUniqueId; +} } // namespace experimental } // namespace intel diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 35073e36e7a5c..63bc9ba4f1ef7 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1664,13 +1664,12 @@ std::vector ProgramManager::getDeviceGlobalEntries( FoundEntries.push_back(DeviceGlobalEntry->second.get()); } return FoundEntries; - } void ProgramManager::addOrInitHostPipeEntry(const void *HostPipePtr, const char *UniqueId) { std::lock_guard HostPipesGuard(m_HostPipesMutex); - + auto ExistingHostPipe = m_HostPipes.find(UniqueId); if (ExistingHostPipe != m_HostPipes.end()) { ExistingHostPipe->second->initialize(HostPipePtr); diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 9ef10ec1bfafd..6f2aa7fe1796d 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -359,10 +359,10 @@ event handler::finalize() { } case detail::CG::ReadWriteHostPipe: { CommandGroup.reset(new detail::CGReadWriteHostPipe( - MImpl->HostPipeName, MImpl->HostPipeBlocking, MImpl->HostPipePtr, MImpl->HostPipeTypeSize, - MImpl->HostPipeRead, std::move(MArgsStorage), std::move(MAccStorage), - std::move(MSharedPtrStorage), std::move(MRequirements), - std::move(MEvents), MCodeLoc)); + MImpl->HostPipeName, MImpl->HostPipeBlocking, MImpl->HostPipePtr, + MImpl->HostPipeTypeSize, MImpl->HostPipeRead, std::move(MArgsStorage), + std::move(MAccStorage), std::move(MSharedPtrStorage), + std::move(MRequirements), std::move(MEvents), MCodeLoc)); break; } case detail::CG::None: diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index c780b1a7d7d92..6980a3957f750 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -9,12 +9,12 @@ #include #include +#include +#include #include #include #include -#include #include -#include template class TestKernel; @@ -59,10 +59,13 @@ static sycl::unittest::PiImage generateDefaultImage() { } using namespace sycl; -using default_pipe_properties = decltype(sycl::ext::oneapi::experimental::properties(sycl::ext::intel::experimental::uses_valid)); +using default_pipe_properties = + decltype(sycl::ext::oneapi::experimental::properties( + sycl::ext::intel::experimental::uses_valid)); class PipeID; -using Pipe = sycl::ext::intel::experimental::pipe; +using Pipe = sycl::ext::intel::experimental::pipe; pi_event READ = reinterpret_cast(0); pi_event WRITE = reinterpret_cast(1); @@ -127,7 +130,7 @@ TEST_F(PipeTest, Basic) { pi_device_binary_struct pi_device_binary = Img.convertToNativeType(); hostPipeEntry->initialize((detail::RTDeviceBinaryImage *)&pi_device_binary); - + const std::string pipe_name = hostPipeEntry->MUniqueId; int host_pipe_read_data; From 61fbe0c0b9ba1f3faad3083a8a376f15287e1d18 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 15 Mar 2023 11:03:09 -0700 Subject: [PATCH 22/56] fix unit tests --- sycl/test/abi/layout_handler.cpp | 3 +- sycl/test/abi/sycl_symbols_linux.dump | 1 + sycl/test/abi/symbol_size_alignment.cpp | 4 +- .../extensions/properties/properties_pipe.cpp | 48 +++++++---------- sycl/unittests/helpers/PiImage.hpp | 20 ++++++++ .../pipes/host_pipe_registration.cpp | 51 +++++++++---------- 6 files changed, 68 insertions(+), 59 deletions(-) diff --git a/sycl/test/abi/layout_handler.cpp b/sycl/test/abi/layout_handler.cpp index 2117e49502799..4e07baead0642 100644 --- a/sycl/test/abi/layout_handler.cpp +++ b/sycl/test/abi/layout_handler.cpp @@ -1,5 +1,4 @@ -// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s -// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s +// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s -o %t.out | FileCheck %s // REQUIRES: linux // UNSUPPORTED: libcxx diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index aa13d320558df..f76fd3a8a3db2 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3655,6 +3655,7 @@ _ZN4sycl3_V120aligned_alloc_sharedEmmRKNS0_6deviceERKNS0_7contextERKNS0_6detail1 _ZN4sycl3_V122accelerator_selector_vERKNS0_6deviceE _ZN4sycl3_V13ext5intel12experimental15online_compilerILNS3_15source_languageE0EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISE_EEEEES8_IhSaIhEERKSE_DpRKT_ _ZN4sycl3_V13ext5intel12experimental15online_compilerILNS3_15source_languageE1EE7compileIJSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISE_EEEEES8_IhSaIhEERKSE_DpRKT_ +_ZN4sycl3_V13ext5intel12experimental9pipe_base13get_pipe_nameB5cxx11EPKv _ZN4sycl3_V13ext6oneapi10level_zero10make_eventERKNS0_7contextEmb _ZN4sycl3_V13ext6oneapi10level_zero10make_queueERKNS0_7contextERKNS0_6deviceEmb _ZN4sycl3_V13ext6oneapi10level_zero10make_queueERKNS0_7contextEmb diff --git a/sycl/test/abi/symbol_size_alignment.cpp b/sycl/test/abi/symbol_size_alignment.cpp index 8329cd53ab16b..86b81bc40bad0 100644 --- a/sycl/test/abi/symbol_size_alignment.cpp +++ b/sycl/test/abi/symbol_size_alignment.cpp @@ -52,9 +52,9 @@ int main() { check(); check(); #ifdef _MSC_VER - check(); // TODO double check whether this is needed + check(); // TODO double check whether this is needed #else - check(); // TODO double check + check(); // TODO double check #endif check, 16, 8>(); check(); diff --git a/sycl/test/extensions/properties/properties_pipe.cpp b/sycl/test/extensions/properties/properties_pipe.cpp index 2b4799ca9ba1e..b9c10a8f0cf88 100644 --- a/sycl/test/extensions/properties/properties_pipe.cpp +++ b/sycl/test/extensions/properties/properties_pipe.cpp @@ -8,7 +8,7 @@ using namespace sycl::ext; constexpr sycl::ext::intel::experimental::protocol_name TestProtocol = - sycl::ext::intel::experimental::protocol_name::AVALON; + sycl::ext::intel::experimental::protocol_name::AVALON_STREAMING; int main() { // Check that is_property_key is correctly specialized. @@ -20,8 +20,6 @@ int main() { sycl::ext::intel::experimental::bits_per_symbol_key>::value); static_assert(sycl::ext::oneapi::experimental::is_property_key< sycl::ext::intel::experimental::uses_valid_key>::value); - static_assert(sycl::ext::oneapi::experimental::is_property_key< - sycl::ext::intel::experimental::uses_ready_key>::value); static_assert(sycl::ext::oneapi::experimental::is_property_key< sycl::ext::intel::experimental::in_csr_key>::value); static_assert( @@ -51,17 +49,6 @@ int main() { static_assert( sycl::ext::oneapi::experimental::is_property_value< decltype(sycl::ext::intel::experimental::uses_valid_off)>::value); - - static_assert( - sycl::ext::oneapi::experimental::is_property_value< - decltype(sycl::ext::intel::experimental::uses_ready)>::value); - static_assert( - sycl::ext::oneapi::experimental::is_property_value< - decltype(sycl::ext::intel::experimental::uses_ready_on)>::value); - static_assert( - sycl::ext::oneapi::experimental::is_property_value< - decltype(sycl::ext::intel::experimental::uses_ready_off)>::value); - static_assert(sycl::ext::oneapi::experimental::is_property_value< decltype(sycl::ext::intel::experimental::in_csr)>::value); static_assert(sycl::ext::oneapi::experimental::is_property_value< @@ -85,18 +72,19 @@ int main() { value); static_assert( sycl::ext::oneapi::experimental::is_property_value< - decltype(sycl::ext::intel::experimental::protocol_avalon)>::value); + decltype(sycl::ext::intel::experimental::protocol_avalon_streaming)>::value); static_assert(sycl::ext::oneapi::experimental::is_property_value< - decltype(sycl::ext::intel::experimental::protocol_axi)>::value); + decltype(sycl::ext::intel::experimental::protocol_avalon_streaming_uses_ready)>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::protocol_avalon_mm)>::value); + static_assert(sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::protocol_avalon_mm_uses_ready)>::value); // Checks that fully specialized properties are the same as the templated // variants. static_assert(std::is_same_v< decltype(sycl::ext::intel::experimental::uses_valid_on), decltype(sycl::ext::intel::experimental::uses_valid)>); - static_assert(std::is_same_v< - decltype(sycl::ext::intel::experimental::uses_ready_off), - decltype(sycl::ext::intel::experimental::uses_ready)>); static_assert( std::is_same_v)>); @@ -107,12 +95,20 @@ int main() { first_symbol_in_high_order_bits)>); static_assert( std::is_same_v< - decltype(sycl::ext::intel::experimental::protocol_avalon), + decltype(sycl::ext::intel::experimental::protocol_avalon_streaming), decltype(sycl::ext::intel::experimental::protocol)>); static_assert(std::is_same_v< - decltype(sycl::ext::intel::experimental::protocol_axi), + decltype(sycl::ext::intel::experimental::protocol_avalon_streaming_uses_ready), + decltype(sycl::ext::intel::experimental::protocol< + sycl::ext::intel::experimental::protocol_name::AVALON_STREAMING_USES_READY>)>); + static_assert(std::is_same_v< + decltype(sycl::ext::intel::experimental::protocol_avalon_mm), decltype(sycl::ext::intel::experimental::protocol< - sycl::ext::intel::experimental::protocol_name::AXI>)>); + sycl::ext::intel::experimental::protocol_name::AVALON_MM>)>); + static_assert(std::is_same_v< + decltype(sycl::ext::intel::experimental::protocol_avalon_mm_uses_ready), + decltype(sycl::ext::intel::experimental::protocol< + sycl::ext::intel::experimental::protocol_name::AVALON_MM_USES_READY>)>); // Check that property lists will accept the new properties. using P = decltype(sycl::ext::oneapi::experimental::properties( @@ -120,10 +116,9 @@ int main() { sycl::ext::intel::experimental::ready_latency<1>, sycl::ext::intel::experimental::bits_per_symbol<2>, sycl::ext::intel::experimental::uses_valid, - sycl::ext::intel::experimental::uses_ready, sycl::ext::intel::experimental::in_csr, sycl::ext::intel::experimental::first_symbol_in_high_order_bits_off, - sycl::ext::intel::experimental::protocol_avalon)); + sycl::ext::intel::experimental::protocol_avalon_streaming)); static_assert(sycl::ext::oneapi::experimental::is_property_list_v

); static_assert( P::has_property()); @@ -133,8 +128,6 @@ int main() { P::has_property()); static_assert( P::has_property()); - static_assert( - P::has_property()); static_assert(P::has_property()); static_assert(P::has_property()); @@ -153,9 +146,6 @@ int main() { static_assert( P::get_property() == sycl::ext::intel::experimental::uses_valid); - static_assert( - P::get_property() == - sycl::ext::intel::experimental::uses_ready); static_assert(P::get_property() == sycl::ext::intel::experimental::in_csr); static_assert( diff --git a/sycl/unittests/helpers/PiImage.hpp b/sycl/unittests/helpers/PiImage.hpp index 38b06eef6d242..eea27eab02296 100644 --- a/sycl/unittests/helpers/PiImage.hpp +++ b/sycl/unittests/helpers/PiImage.hpp @@ -478,6 +478,26 @@ inline PiProperty makeDeviceGlobalInfo(const std::string &Name, return Prop; } +/// Utility function to create a host pipe info property. +/// +/// \param Name is the name of the hostpipe name. +/// \param TypeSize is the size of the underlying type in the hostpipe. +/// decorated. +inline PiProperty makeHostPipeInfo(const std::string &Name, + const uint32_t TypeSize) { + constexpr size_t BYTES_FOR_SIZE = 8; + const std::uint64_t BytesForArgs = sizeof(std::uint32_t); + std::vector DescData; + DescData.resize(BYTES_FOR_SIZE + BytesForArgs); + std::memcpy(DescData.data(), &BytesForArgs, sizeof(BytesForArgs)); + std::memcpy(DescData.data() + BYTES_FOR_SIZE, &TypeSize, sizeof(TypeSize)); + + PiProperty Prop{Name, DescData, PI_PROPERTY_TYPE_BYTE_ARRAY}; + + return Prop; +} + + /// Utility function to add aspects to property set. inline PiProperty makeAspectsProp(const std::vector &Aspects) { const size_t BYTES_FOR_SIZE = 8; diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 6980a3957f750..b7f5d6a3e8da0 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -9,12 +9,12 @@ #include #include -#include -#include #include #include #include +#include #include +#include template class TestKernel; @@ -38,10 +38,24 @@ template struct KernelInfo> { } // __SYCL_INLINE_VER_NAMESPACE(_V1) } // namespace sycl + +using namespace sycl; +using default_pipe_properties = decltype(sycl::ext::oneapi::experimental::properties(sycl::ext::intel::experimental::uses_valid)); + +class PipeID; +using Pipe = sycl::ext::intel::experimental::pipe; + static sycl::unittest::PiImage generateDefaultImage() { using namespace sycl::unittest; + sycl::detail::host_pipe_map::add(Pipe::get_host_ptr(), "test_host_pipe_unique_id"); + PiPropertySet PropSet; + PiProperty HostPipeInfo = + makeHostPipeInfo("test_host_pipe_unique_id", sizeof(int)); + PropSet.insert(__SYCL_PI_PROPERTY_SET_SYCL_HOST_PIPES, + PiArray{std::move(HostPipeInfo)}); + std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data @@ -58,15 +72,6 @@ static sycl::unittest::PiImage generateDefaultImage() { return Img; } -using namespace sycl; -using default_pipe_properties = - decltype(sycl::ext::oneapi::experimental::properties( - sycl::ext::intel::experimental::uses_valid)); - -class PipeID; -using Pipe = sycl::ext::intel::experimental::pipe; - pi_event READ = reinterpret_cast(0); pi_event WRITE = reinterpret_cast(1); static constexpr int PipeReadVal = 8; @@ -75,14 +80,12 @@ pi_result redefinedEnqueueReadHostPipe(pi_queue, pi_program, const char *, pi_bool, void *ptr, size_t, pi_uint32, const pi_event *, pi_event *event) { *(((int *)ptr)) = PipeReadVal; - *event = READ; return PI_SUCCESS; } pi_result redefinedEnqueueWriteHostPipe(pi_queue, pi_program, const char *, pi_bool, void *ptr, size_t, pi_uint32, const pi_event *, pi_event *event) { PipeWriteVal = 9; - *event = WRITE; return PI_SUCCESS; } @@ -116,23 +119,17 @@ class PipeTest : public ::testing::Test { TEST_F(PipeTest, Basic) { - // Fake registration of host pipes - sycl::detail::host_pipe_map::add(Pipe::get_host_ptr(), - "test_host_pipe_unique_id"); - // Device registration static sycl::unittest::PiImage Img = generateDefaultImage(); static sycl::unittest::PiImageArray<1> ImgArray{&Img}; + // Get the hostpipe const void *HostPipePtr = Pipe::get_host_ptr(); detail::HostPipeMapEntry *hostPipeEntry = detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); - - pi_device_binary_struct pi_device_binary = Img.convertToNativeType(); - hostPipeEntry->initialize((detail::RTDeviceBinaryImage *)&pi_device_binary); - const std::string pipe_name = hostPipeEntry->MUniqueId; - + + // Testing read int host_pipe_read_data; void *data_ptr = &host_pipe_read_data; event e = q.submit([=](handler &CGH) { @@ -141,12 +138,14 @@ TEST_F(PipeTest, Basic) { }); e.wait(); assert(host_pipe_read_data == PipeReadVal); - int tmp = {9}; - data_ptr = &tmp; + + // Testing write + int tmp = 9; + void * data_ptr2 = &tmp; event e_write = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), true, + CGH.read_write_host_pipe(pipe_name, data_ptr2, sizeof(int), true, false /* write */); }); e_write.wait(); assert(PipeWriteVal == 9); -} \ No newline at end of file +} From 57914031b6bdb2da37d8e2b6f58b9f191e76c0d2 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 15 Mar 2023 11:04:47 -0700 Subject: [PATCH 23/56] run clang format --- .../extensions/properties/properties_pipe.cpp | 43 +++++++++++-------- sycl/unittests/helpers/PiImage.hpp | 1 - .../pipes/host_pipe_registration.cpp | 20 +++++---- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/sycl/test/extensions/properties/properties_pipe.cpp b/sycl/test/extensions/properties/properties_pipe.cpp index b9c10a8f0cf88..7e6dc53244b23 100644 --- a/sycl/test/extensions/properties/properties_pipe.cpp +++ b/sycl/test/extensions/properties/properties_pipe.cpp @@ -72,13 +72,17 @@ int main() { value); static_assert( sycl::ext::oneapi::experimental::is_property_value< - decltype(sycl::ext::intel::experimental::protocol_avalon_streaming)>::value); - static_assert(sycl::ext::oneapi::experimental::is_property_value< - decltype(sycl::ext::intel::experimental::protocol_avalon_streaming_uses_ready)>::value); + decltype(sycl::ext::intel::experimental::protocol_avalon_streaming)>:: + value); static_assert(sycl::ext::oneapi::experimental::is_property_value< - decltype(sycl::ext::intel::experimental::protocol_avalon_mm)>::value); + decltype(sycl::ext::intel::experimental:: + protocol_avalon_streaming_uses_ready)>::value); + static_assert( + sycl::ext::oneapi::experimental::is_property_value< + decltype(sycl::ext::intel::experimental::protocol_avalon_mm)>::value); static_assert(sycl::ext::oneapi::experimental::is_property_value< - decltype(sycl::ext::intel::experimental::protocol_avalon_mm_uses_ready)>::value); + decltype(sycl::ext::intel::experimental:: + protocol_avalon_mm_uses_ready)>::value); // Checks that fully specialized properties are the same as the templated // variants. @@ -97,18 +101,23 @@ int main() { std::is_same_v< decltype(sycl::ext::intel::experimental::protocol_avalon_streaming), decltype(sycl::ext::intel::experimental::protocol)>); - static_assert(std::is_same_v< - decltype(sycl::ext::intel::experimental::protocol_avalon_streaming_uses_ready), - decltype(sycl::ext::intel::experimental::protocol< - sycl::ext::intel::experimental::protocol_name::AVALON_STREAMING_USES_READY>)>); - static_assert(std::is_same_v< - decltype(sycl::ext::intel::experimental::protocol_avalon_mm), - decltype(sycl::ext::intel::experimental::protocol< - sycl::ext::intel::experimental::protocol_name::AVALON_MM>)>); - static_assert(std::is_same_v< - decltype(sycl::ext::intel::experimental::protocol_avalon_mm_uses_ready), - decltype(sycl::ext::intel::experimental::protocol< - sycl::ext::intel::experimental::protocol_name::AVALON_MM_USES_READY>)>); + static_assert( + std::is_same_v)>); + static_assert( + std::is_same_v< + decltype(sycl::ext::intel::experimental::protocol_avalon_mm), + decltype(sycl::ext::intel::experimental::protocol< + sycl::ext::intel::experimental::protocol_name::AVALON_MM>)>); + static_assert( + std::is_same_v)>); // Check that property lists will accept the new properties. using P = decltype(sycl::ext::oneapi::experimental::properties( diff --git a/sycl/unittests/helpers/PiImage.hpp b/sycl/unittests/helpers/PiImage.hpp index eea27eab02296..b56aa1bb7f12c 100644 --- a/sycl/unittests/helpers/PiImage.hpp +++ b/sycl/unittests/helpers/PiImage.hpp @@ -497,7 +497,6 @@ inline PiProperty makeHostPipeInfo(const std::string &Name, return Prop; } - /// Utility function to add aspects to property set. inline PiProperty makeAspectsProp(const std::vector &Aspects) { const size_t BYTES_FOR_SIZE = 8; diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index b7f5d6a3e8da0..e584a1f759321 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -9,12 +9,12 @@ #include #include +#include +#include #include #include #include -#include #include -#include template class TestKernel; @@ -38,17 +38,20 @@ template struct KernelInfo> { } // __SYCL_INLINE_VER_NAMESPACE(_V1) } // namespace sycl - using namespace sycl; -using default_pipe_properties = decltype(sycl::ext::oneapi::experimental::properties(sycl::ext::intel::experimental::uses_valid)); +using default_pipe_properties = + decltype(sycl::ext::oneapi::experimental::properties( + sycl::ext::intel::experimental::uses_valid)); class PipeID; -using Pipe = sycl::ext::intel::experimental::pipe; +using Pipe = sycl::ext::intel::experimental::pipe; static sycl::unittest::PiImage generateDefaultImage() { using namespace sycl::unittest; - sycl::detail::host_pipe_map::add(Pipe::get_host_ptr(), "test_host_pipe_unique_id"); + sycl::detail::host_pipe_map::add(Pipe::get_host_ptr(), + "test_host_pipe_unique_id"); PiPropertySet PropSet; PiProperty HostPipeInfo = @@ -56,7 +59,6 @@ static sycl::unittest::PiImage generateDefaultImage() { PropSet.insert(__SYCL_PI_PROPERTY_SET_SYCL_HOST_PIPES, PiArray{std::move(HostPipeInfo)}); - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data PiArray Entries = makeEmptyKernels({"TestKernel"}); @@ -128,7 +130,7 @@ TEST_F(PipeTest, Basic) { detail::HostPipeMapEntry *hostPipeEntry = detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); const std::string pipe_name = hostPipeEntry->MUniqueId; - + // Testing read int host_pipe_read_data; void *data_ptr = &host_pipe_read_data; @@ -141,7 +143,7 @@ TEST_F(PipeTest, Basic) { // Testing write int tmp = 9; - void * data_ptr2 = &tmp; + void *data_ptr2 = &tmp; event e_write = q.submit([=](handler &CGH) { CGH.read_write_host_pipe(pipe_name, data_ptr2, sizeof(int), true, false /* write */); From ab0fafa61b08fc15b7f58a7fc33fbebe22f5fae3 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 15 Mar 2023 11:24:53 -0700 Subject: [PATCH 24/56] fix pipe property test --- sycl/test/extensions/properties/properties_pipe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test/extensions/properties/properties_pipe.cpp b/sycl/test/extensions/properties/properties_pipe.cpp index 7e6dc53244b23..70e2c30078db3 100644 --- a/sycl/test/extensions/properties/properties_pipe.cpp +++ b/sycl/test/extensions/properties/properties_pipe.cpp @@ -163,5 +163,5 @@ int main() { sycl::ext::intel::experimental::first_symbol_in_high_order_bits_off); static_assert( P::get_property() == - sycl::ext::intel::experimental::protocol_avalon); + sycl::ext::intel::experimental::protocol_avalon_streaming); } From d0fb7d7a216b29ab08e8ea2bfcdb33ce2f096465 Mon Sep 17 00:00:00 2001 From: "Ho, Robert" Date: Wed, 15 Mar 2023 12:39:17 -0700 Subject: [PATCH 25/56] Collect host pipe attribute functions and cleanup comments (cherry picked from commit 988ae67b0d924e48b68cf26a4ebe5bb0e5b2ead6) --- llvm/include/llvm/SYCLLowerIR/HostPipes.h | 30 ++++++++++++------ llvm/include/llvm/SYCLLowerIR/SYCLUtils.h | 5 --- .../SYCLLowerIR/CompileTimePropertiesPass.cpp | 5 +-- llvm/lib/SYCLLowerIR/HostPipes.cpp | 31 +++++++++---------- .../host-pipes/basic.ll | 2 +- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/llvm/include/llvm/SYCLLowerIR/HostPipes.h b/llvm/include/llvm/SYCLLowerIR/HostPipes.h index b4cd8ccb82690..a243fc029c90a 100644 --- a/llvm/include/llvm/SYCLLowerIR/HostPipes.h +++ b/llvm/include/llvm/SYCLLowerIR/HostPipes.h @@ -1,4 +1,4 @@ -//===--- HostPipes.h - get required into about SYCL Device Globals ----===// +//===------- 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. @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// // // The file contains a number of functions to extract corresponding attributes -// of the device global variables and save them as a property set for the +// of the host pipe global variables and save them as a property set for the // runtime. //===----------------------------------------------------------------------===// @@ -24,34 +24,44 @@ class GlobalVariable; class Module; class StringRef; -// Represents a device global variable - at SYCL RT level device global +// 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 device global variable. + // Encodes size of the underlying type T of the host pipe variable. uint32_t Size; }; using HostPipePropertyMapTy = MapVector>; -/// Searches given module for occurrences of device global variable-specific -/// metadata and builds "device global variable name" -> +/// 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 "device global variable name" -> vector<"variable properties"> +/// @returns the "host pipe variable name" -> vector<"variable properties"> /// map. HostPipePropertyMapTy collectHostPipeProperties(const Module &M); -/// Returns the unique id for the device global variable. +/// Returns the unique id for the host pipe variable. /// /// @param GV [in] Device Global variable. /// -/// @returns the unique id of the device global variable represented +/// @returns the unique id of the host pipe variable represented /// in the LLVM IR by \c GV. -// StringRef getGlobalVariableUniqueId(const GlobalVariable &GV); +StringRef getHostPipeVariableUniqueId(const GlobalVariable &GV); } // end namespace llvm diff --git a/llvm/include/llvm/SYCLLowerIR/SYCLUtils.h b/llvm/include/llvm/SYCLLowerIR/SYCLUtils.h index 2d82e651b35fb..241859a47426d 100644 --- a/llvm/include/llvm/SYCLLowerIR/SYCLUtils.h +++ b/llvm/include/llvm/SYCLLowerIR/SYCLUtils.h @@ -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; using CallGraphFunctionFilter = @@ -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 diff --git a/llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp b/llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp index cdffd1d0019ef..a4f4b265c4f73 100644 --- a/llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp +++ b/llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp @@ -10,7 +10,8 @@ #include "llvm/SYCLLowerIR/CompileTimePropertiesPass.h" #include "llvm/SYCLLowerIR/DeviceGlobals.h" -#include "llvm/SYCLLowerIR/SYCLUtils.h" +#include "llvm/SYCLLowerIR/HostPipes.h" +// #include "llvm/SYCLLowerIR/SYCLUtils.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/StringMap.h" @@ -303,7 +304,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, diff --git a/llvm/lib/SYCLLowerIR/HostPipes.cpp b/llvm/lib/SYCLLowerIR/HostPipes.cpp index 8b258962b14fc..95b243e2c9447 100644 --- a/llvm/lib/SYCLLowerIR/HostPipes.cpp +++ b/llvm/lib/SYCLLowerIR/HostPipes.cpp @@ -22,10 +22,11 @@ using namespace llvm; namespace { +constexpr StringRef SYCL_HOST_PIPE_ATTR = "sycl-host-pipe"; constexpr StringRef SYCL_HOST_PIPE_SIZE_ATTR = "sycl-host-pipe-size"; constexpr StringRef SYCL_UNIQUE_ID_ATTR = "sycl-unique-id"; -/// Returns the size (in bytes) of the underlying type \c T of the host +/// 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 @@ -35,11 +36,11 @@ constexpr StringRef SYCL_UNIQUE_ID_ATTR = "sycl-unique-id"; /// /// @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 getUnderlyingTypeSize(const GlobalVariable &GV) { +uint32_t getHostPipeTypeSize(const GlobalVariable &GV) { assert(GV.hasAttribute(SYCL_HOST_PIPE_SIZE_ATTR) && - "The device global variable must have the 'sycl-host-pipe-size' " + "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 device global variable"); + "underlying type T of the host pipe variable"); return getAttributeAsInteger(GV, SYCL_HOST_PIPE_SIZE_ATTR); } @@ -47,35 +48,33 @@ uint32_t getUnderlyingTypeSize(const GlobalVariable &GV) { namespace llvm { -/// Return \c true if the variable @GV is a device global variable. +/// 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-size. +/// sycl-host-pipe. /// @param GV [in] A variable to test. /// -/// @return \c true if the variable is a device global variable, \c false +/// @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_SIZE_ATTR); + return GV.hasAttribute(SYCL_HOST_PIPE_ATTR); } -#if 0 -/// Returns the unique id for the device global variable. +/// Returns the unique id for the host pipe variable. /// /// The function gets this value from the LLVM IR attribute \c /// sycl-unique-id. /// /// @param GV [in] Device Global variable. /// -/// @returns the unique id of the device global variable represented +/// @returns the unique id of the host pipe variable represented /// in the LLVM IR by \c GV. -StringRef getGlobalVariableUniqueId(const GlobalVariable &GV) { +StringRef getHostPipeVariableUniqueId(const GlobalVariable &GV) { assert(GV.hasAttribute(SYCL_UNIQUE_ID_ATTR) && - "a 'sycl-unique-id' string must be associated with every device " - "global variable"); + "a 'sycl-unique-id' string must be associated with every host " + "pipe variable"); return GV.getAttribute(SYCL_UNIQUE_ID_ATTR).getValueAsString(); } -#endif HostPipePropertyMapTy collectHostPipeProperties(const Module &M) { HostPipePropertyMapTy HPM; @@ -89,7 +88,7 @@ HostPipePropertyMapTy collectHostPipeProperties(const Module &M) { if (!isHostPipeVariable(GV)) continue; - HPM[getGlobalVariableUniqueId(GV)] = {getUnderlyingTypeSize(GV)}; + HPM[getHostPipeVariableUniqueId(GV)] = {getHostPipeTypeSize(GV)}; } return HPM; diff --git a/llvm/test/SYCLLowerIR/CompileTimePropertiesPass/host-pipes/basic.ll b/llvm/test/SYCLLowerIR/CompileTimePropertiesPass/host-pipes/basic.ll index f6009ad0b4583..5bac4eabe59f5 100644 --- a/llvm/test/SYCLLowerIR/CompileTimePropertiesPass/host-pipes/basic.ll +++ b/llvm/test/SYCLLowerIR/CompileTimePropertiesPass/host-pipes/basic.ll @@ -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-device-global-size"="4" "sycl-unique-id"="_ZN4sycl3_V13ext5intel12experimental9host_pipeI9H2DPipeIDiNS1_6oneapi12experimental10propertiesISt5tupleIJEEEEE6__pipeE" } ; Ensure that the generated metadata nodes are correct ; CHECK-IR-DAG: ![[#MN0]] = !{![[#MN1:]]} From 9884770f86a8fcdd5159e42aacbf99ae98c04239 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 15 Mar 2023 12:44:45 -0700 Subject: [PATCH 26/56] code cleanup --- sycl/unittests/helpers/PiMockPlugin.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/sycl/unittests/helpers/PiMockPlugin.hpp b/sycl/unittests/helpers/PiMockPlugin.hpp index ca3415dad2163..0faa30e9b7407 100644 --- a/sycl/unittests/helpers/PiMockPlugin.hpp +++ b/sycl/unittests/helpers/PiMockPlugin.hpp @@ -1138,9 +1138,6 @@ inline pi_result mock_piGetDeviceAndHostTimer(pi_device device, } return PI_SUCCESS; } -/// -// Host Pipes -/// inline pi_result mock_piextEnqueueReadHostPipe( pi_queue queue, pi_program program, const char *pipe_symbol, From d341a8b598c96e2b47e427de60836842f322e90f Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Thu, 16 Mar 2023 07:52:55 -0700 Subject: [PATCH 27/56] update opencl header function pointer name --- buildbot/dependency.py | 2 +- opencl/CMakeLists.txt | 2 +- sycl/plugins/opencl/pi_opencl.cpp | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/buildbot/dependency.py b/buildbot/dependency.py index cfd3361cb2470..24cc0fd9b4379 100644 --- a/buildbot/dependency.py +++ b/buildbot/dependency.py @@ -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", "d57c0d85426703e3edd366a018a6e7385d534eb3"] # TODO: Remove change once upstream header changed + checkout_cmd = ["git", "checkout", "8f9c175f7e55457662d7fa4e775a234a588f01cd"] # TODO: Remove change once upstream header changed subprocess.check_call(checkout_cmd, cwd=ocl_header_dir) # fetch and build OpenCL ICD loader diff --git a/opencl/CMakeLists.txt b/opencl/CMakeLists.txt index e377b2c19e2bc..37e5e9a11a124 100644 --- a/opencl/CMakeLists.txt +++ b/opencl/CMakeLists.txt @@ -20,7 +20,7 @@ set(OCL_LOADER_REPO # Repo tags/hashes -set(OCL_HEADERS_TAG d57c0d85426703e3edd366a018a6e7385d534eb3) #TODO: Change it back once the official header is in. +set(OCL_HEADERS_TAG 8f9c175f7e55457662d7fa4e775a234a588f01cd) #TODO: Change it back once the official header is in. set(OCL_LOADER_TAG 9a3e962f16f5097d2054233ad8b6dad51b6f41b7) # OpenCL Headers diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index f2896c2bf4914..a4689b7e93589 100644 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -1703,9 +1703,9 @@ pi_result piextEnqueueReadHostPipe(pi_queue queue, pi_program program, return cast(CLErr); } - clEnqueueReadHostPipeIntelFPGA_fn FuncPtr = nullptr; + clEnqueueReadHostPipeINTEL_fn FuncPtr = nullptr; pi_result RetVal = getExtFuncFromContext( + clEnqueueReadHostPipeINTEL_fn>( cast(CLContext), &FuncPtr); if (FuncPtr) { @@ -1714,6 +1714,7 @@ pi_result piextEnqueueReadHostPipe(pi_queue queue, pi_program program, blocking, ptr, size, num_events_in_waitlist, cast(events_waitlist), cast(event))); } + return RetVal; } @@ -1730,16 +1731,19 @@ pi_result piextEnqueueWriteHostPipe(pi_queue queue, pi_program program, if (CLErr != CL_SUCCESS) { return cast(CLErr); } - clEnqueueWriteHostPipeIntelFPGA_fn FuncPtr = nullptr; + + clEnqueueWriteHostPipeINTEL_fn FuncPtr = nullptr; pi_result RetVal = getExtFuncFromContext( + clEnqueueWriteHostPipeINTEL_fn>( cast(CLContext), &FuncPtr); + if (FuncPtr) { RetVal = cast(FuncPtr( cast(queue), cast(program), pipe_symbol, blocking, ptr, size, num_events_in_waitlist, cast(events_waitlist), cast(event))); } + return RetVal; } From 6af1f96df25ac4acb9117916bdff30e073c94343 Mon Sep 17 00:00:00 2001 From: "Ho, Robert" Date: Thu, 16 Mar 2023 05:06:26 -0700 Subject: [PATCH 28/56] Fix misnamed attribute in host pipe lit test (cherry picked from commit 449962481d195f44ada7a888a592b3098b3c2a59) --- .../SYCLLowerIR/CompileTimePropertiesPass/host-pipes/basic.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/SYCLLowerIR/CompileTimePropertiesPass/host-pipes/basic.ll b/llvm/test/SYCLLowerIR/CompileTimePropertiesPass/host-pipes/basic.ll index 5bac4eabe59f5..8619156b79e7d 100644 --- a/llvm/test/SYCLLowerIR/CompileTimePropertiesPass/host-pipes/basic.ll +++ b/llvm/test/SYCLLowerIR/CompileTimePropertiesPass/host-pipes/basic.ll @@ -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-device-global-size"="4" "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:]]} From d393163c8ad2d45018146600f88a9bcfbffd0f80 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Thu, 16 Mar 2023 12:19:17 -0700 Subject: [PATCH 29/56] add __SYCL_EXPORT to the header as well --- sycl/include/sycl/ext/intel/experimental/pipes.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index f497762f8dd22..312e9e19f6f06 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -57,7 +57,7 @@ class pipe_base { pipe_base(); ~pipe_base(); - static std::string get_pipe_name(const void *HostPipePtr); + __SYCL_EXPORT static std::string get_pipe_name(const void *HostPipePtr); }; template Date: Thu, 16 Mar 2023 13:46:15 -0700 Subject: [PATCH 30/56] update windows symbol dump --- sycl/test/abi/sycl_symbols_windows.dump | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index ece5c55ac03a3..631cbc25bbe00 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -998,6 +998,7 @@ ?get_max_statement_size@stream@_V1@sycl@@QEBA_KXZ ?get_max_statement_size@stream_impl@detail@_V1@sycl@@QEBA_KXZ ?get_name@kernel_id@_V1@sycl@@QEBAPEBDXZ +?get_pipe_name@pipe_base@experimental@intel@ext@_V1@sycl@@KA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBX@Z ?get_pitch@image_impl@detail@_V1@sycl@@QEBA?AV?$range@$01@34@XZ ?get_pitch@image_plain@detail@_V1@sycl@@IEBA?AV?$range@$01@34@XZ ?get_platform@context@_V1@sycl@@QEBA?AVplatform@23@XZ @@ -1137,6 +1138,7 @@ ?prefetch_usm@MemoryManager@detail@_V1@sycl@@SAXPEAXV?$shared_ptr@Vqueue_impl@detail@_V1@sycl@@@std@@_KV?$vector@PEAU_pi_event@@V?$allocator@PEAU_pi_event@@@std@@@6@PEAPEAU_pi_event@@@Z ?processArg@handler@_V1@sycl@@AEAAXPEAXAEBW4kernel_param_kind_t@detail@23@H_KAEA_K_N4@Z ?query@tls_code_loc_t@detail@_V1@sycl@@QEAAAEBUcode_location@234@XZ +?read_write_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N3@Z ?reduComputeWGSize@detail@_V1@sycl@@YA_K_K0AEA_K@Z ?reduGetMaxNumConcurrentWorkGroups@detail@_V1@sycl@@YAIV?$shared_ptr@Vqueue_impl@detail@_V1@sycl@@@std@@@Z ?reduGetMaxWGSize@detail@_V1@sycl@@YA_KV?$shared_ptr@Vqueue_impl@detail@_V1@sycl@@@std@@_K@Z From 30eace189c38202fefc5378435b92ced4cad8f43 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Sat, 18 Mar 2023 08:28:32 -0700 Subject: [PATCH 31/56] Updated default value for the pipe properties --- sycl/include/sycl/ext/intel/experimental/pipes.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 312e9e19f6f06..aca31dfc28a82 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -383,7 +383,7 @@ class pipe : public pipe_base { ready_latency_key>::template get(0); static constexpr int32_t m_bits_per_symbol = detail::ValueOrDefault<_propertiesT, - bits_per_symbol_key>::template get(0); + bits_per_symbol_key>::template get(1); static constexpr bool m_uses_valid = detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get( true); @@ -393,7 +393,7 @@ class pipe : public pipe_base { first_symbol_in_high_order_bits_key>::template get(0); static constexpr protocol_name m_protocol = detail::ValueOrDefault<_propertiesT, protocol_key>::template get< - protocol_name>(protocol_name::AVALON_STREAMING); + protocol_name>(protocol_name::AVALON_STREAMING_USES_READY); public: static constexpr struct ConstantPipeStorageExp m_Storage = { From cade6518c18ffc0fbe52f644e5e1ef016053e0a1 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Mon, 20 Mar 2023 07:51:56 -0700 Subject: [PATCH 32/56] fixup --- buildbot/dependency.py | 2 +- opencl/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildbot/dependency.py b/buildbot/dependency.py index 24cc0fd9b4379..da49091ced41a 100644 --- a/buildbot/dependency.py +++ b/buildbot/dependency.py @@ -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", "8f9c175f7e55457662d7fa4e775a234a588f01cd"] # TODO: Remove change once upstream header changed + checkout_cmd = ["git", "checkout", "5b25fed2d0556ad429f6f5a826e06b7f4a6aa646"] # TODO: Remove change once upstream header changed subprocess.check_call(checkout_cmd, cwd=ocl_header_dir) # fetch and build OpenCL ICD loader diff --git a/opencl/CMakeLists.txt b/opencl/CMakeLists.txt index 37e5e9a11a124..db8d353411089 100644 --- a/opencl/CMakeLists.txt +++ b/opencl/CMakeLists.txt @@ -20,7 +20,7 @@ set(OCL_LOADER_REPO # Repo tags/hashes -set(OCL_HEADERS_TAG 8f9c175f7e55457662d7fa4e775a234a588f01cd) #TODO: Change it back once the official header is in. +set(OCL_HEADERS_TAG 5b25fed2d0556ad429f6f5a826e06b7f4a6aa646) #TODO: Change it back once the official header is in. set(OCL_LOADER_TAG 9a3e962f16f5097d2054233ad8b6dad51b6f41b7) # OpenCL Headers From ae0988b0c0aecda15fc1265050c2ce330819a53a Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 21 Mar 2023 07:33:49 -0700 Subject: [PATCH 33/56] Update OPENCL Header commit --- buildbot/dependency.py | 6 +++--- opencl/CMakeLists.txt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/buildbot/dependency.py b/buildbot/dependency.py index da49091ced41a..e79eae2b62cc1 100644 --- a/buildbot/dependency.py +++ b/buildbot/dependency.py @@ -49,8 +49,8 @@ def do_dependency(args): # fetch OpenCL headers ocl_header_dir = os.path.join(args.obj_dir, "OpenCL-Headers") if not os.path.isdir(ocl_header_dir): - clone_cmd = ["git", "clone", "https://github.com/zibaiwan/OpenCL-Headers", - "OpenCL-Headers", "-b", "host-pipe-final"] # TODO: Remove change once upstream header changed + clone_cmd = ["git", "clone", "https://github.com/KhronosGroup/OpenCL-Headers", + "OpenCL-Headers", "-b", "main"] subprocess.check_call(clone_cmd, cwd=args.obj_dir) else: fetch_cmd = ["git", "pull", "--ff", "--ff-only", "origin"] @@ -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", "5b25fed2d0556ad429f6f5a826e06b7f4a6aa646"] # TODO: Remove change once upstream header changed + checkout_cmd = ["git", "checkout", "9ddb236e6eb3cf844f9e2f81677e1045f9bf838e"] subprocess.check_call(checkout_cmd, cwd=ocl_header_dir) # fetch and build OpenCL ICD loader diff --git a/opencl/CMakeLists.txt b/opencl/CMakeLists.txt index db8d353411089..2f4e7c9941af6 100644 --- a/opencl/CMakeLists.txt +++ b/opencl/CMakeLists.txt @@ -14,13 +14,13 @@ endif() # Repo URLs set(OCL_HEADERS_REPO - "https://github.com/zibaiwan/OpenCL-Headers.git") #TODO: Change it back once the official header is in. + "https://github.com/KhronosGroup/OpenCL-Headers.git") set(OCL_LOADER_REPO "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git") # Repo tags/hashes -set(OCL_HEADERS_TAG 5b25fed2d0556ad429f6f5a826e06b7f4a6aa646) #TODO: Change it back once the official header is in. +set(OCL_HEADERS_TAG 9ddb236e6eb3cf844f9e2f81677e1045f9bf838e) set(OCL_LOADER_TAG 9a3e962f16f5097d2054233ad8b6dad51b6f41b7) # OpenCL Headers From a41263a48aa346445d77b0afdf00aec72ded0718 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 21 Mar 2023 07:37:23 -0700 Subject: [PATCH 34/56] Comments fixup --- sycl/test/abi/symbol_size_alignment.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/test/abi/symbol_size_alignment.cpp b/sycl/test/abi/symbol_size_alignment.cpp index 86b81bc40bad0..2372c13d65e06 100644 --- a/sycl/test/abi/symbol_size_alignment.cpp +++ b/sycl/test/abi/symbol_size_alignment.cpp @@ -52,9 +52,9 @@ int main() { check(); check(); #ifdef _MSC_VER - check(); // TODO double check whether this is needed + check(); #else - check(); // TODO double check + check(); #endif check, 16, 8>(); check(); From 7878b2609cbfe131c30d20b4ac2eb8f36be68e76 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 21 Mar 2023 07:58:09 -0700 Subject: [PATCH 35/56] Update error messages when the device side API is called on the host --- .../sycl/ext/intel/experimental/pipes.hpp | 8 ++++---- sycl/include/sycl/ext/intel/pipes.hpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index aca31dfc28a82..248db8cd306e3 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -181,7 +181,7 @@ class pipe : public pipe_base { (void)Properties; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -230,7 +230,7 @@ class pipe : public pipe_base { (void)Properties; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -320,7 +320,7 @@ class pipe : public pipe_base { (void)Properties; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } @@ -365,7 +365,7 @@ class pipe : public pipe_base { (void)Properties; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } diff --git a/sycl/include/sycl/ext/intel/pipes.hpp b/sycl/include/sycl/ext/intel/pipes.hpp index 61a9e742e5cb1..d13befd0bcb92 100644 --- a/sycl/include/sycl/ext/intel/pipes.hpp +++ b/sycl/include/sycl/ext/intel/pipes.hpp @@ -35,7 +35,7 @@ template class pipe { (void)_Success; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } @@ -52,7 +52,7 @@ template class pipe { (void)_Data; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } @@ -69,7 +69,7 @@ template class pipe { #else throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } @@ -84,7 +84,7 @@ template class pipe { (void)_Data; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } @@ -137,7 +137,7 @@ class kernel_readable_io_pipe { (void)_Success; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } @@ -154,7 +154,7 @@ class kernel_readable_io_pipe { #else throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } @@ -187,7 +187,7 @@ class kernel_writeable_io_pipe { (void)_Success; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } @@ -203,7 +203,7 @@ class kernel_writeable_io_pipe { (void)_Data; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Pipes are not supported on a host device."); + "Device-side API are not supported on a host device. Please use host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } From ddcc06769329f1d55f863f9ac7cb428986d36c2b Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 21 Mar 2023 08:08:25 -0700 Subject: [PATCH 36/56] fix error messages --- sycl/include/sycl/ext/intel/experimental/pipes.hpp | 2 +- sycl/include/sycl/ext/intel/pipes.hpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 248db8cd306e3..38f21c632e1d0 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -320,7 +320,7 @@ class pipe : public pipe_base { (void)Properties; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead.."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } diff --git a/sycl/include/sycl/ext/intel/pipes.hpp b/sycl/include/sycl/ext/intel/pipes.hpp index d13befd0bcb92..72d1a358c8bb7 100644 --- a/sycl/include/sycl/ext/intel/pipes.hpp +++ b/sycl/include/sycl/ext/intel/pipes.hpp @@ -35,7 +35,7 @@ template class pipe { (void)_Success; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead.."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -52,7 +52,7 @@ template class pipe { (void)_Data; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead.."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -84,7 +84,7 @@ template class pipe { (void)_Data; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead.."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -137,7 +137,7 @@ class kernel_readable_io_pipe { (void)_Success; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead.."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -154,7 +154,7 @@ class kernel_readable_io_pipe { #else throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead.."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -187,7 +187,7 @@ class kernel_writeable_io_pipe { (void)_Success; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead.."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -203,7 +203,7 @@ class kernel_writeable_io_pipe { (void)_Data; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead.."); + "Device-side API are not supported on a host device. Please use host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } From 400a10a04df89522ebec5a287a981a678c3a7a34 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Fri, 24 Mar 2023 08:18:58 -0700 Subject: [PATCH 37/56] update default value of bits per symbol to 8 --- sycl/include/sycl/ext/intel/experimental/pipes.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 38f21c632e1d0..f0d80f34719a8 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -383,7 +383,7 @@ class pipe : public pipe_base { ready_latency_key>::template get(0); static constexpr int32_t m_bits_per_symbol = detail::ValueOrDefault<_propertiesT, - bits_per_symbol_key>::template get(1); + bits_per_symbol_key>::template get(8); static constexpr bool m_uses_valid = detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get( true); From 666af1c8e0c6f1b71ba8eb2836fe90f407c340d3 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Fri, 24 Mar 2023 13:06:07 -0700 Subject: [PATCH 38/56] various fixes and style changes --- .../SYCLLowerIR/CompileTimePropertiesPass.cpp | 1 - .../sycl/ext/intel/experimental/pipes.hpp | 46 +++++-------------- .../sycl/ext/oneapi/properties/properties.hpp | 18 ++++++++ sycl/include/sycl/handler.hpp | 2 +- sycl/source/detail/pipes.cpp | 2 +- .../program_manager/program_manager.cpp | 10 ++-- sycl/source/handler.cpp | 2 +- sycl/test/abi/sycl_symbols_linux.dump | 4 +- sycl/test/abi/sycl_symbols_windows.dump | 2 +- .../pipes/host_pipe_registration.cpp | 4 +- 10 files changed, 41 insertions(+), 50 deletions(-) diff --git a/llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp b/llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp index a4f4b265c4f73..353e3ad551f6e 100644 --- a/llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp +++ b/llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp @@ -11,7 +11,6 @@ #include "llvm/SYCLLowerIR/CompileTimePropertiesPass.h" #include "llvm/SYCLLowerIR/DeviceGlobals.h" #include "llvm/SYCLLowerIR/HostPipes.h" -// #include "llvm/SYCLLowerIR/SYCLUtils.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/StringMap.h" diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index f0d80f34719a8..78e5520f1af56 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -30,26 +30,6 @@ namespace ext { namespace intel { namespace experimental { -namespace detail { -template -struct ValueOrDefault { - template static constexpr ValT get(ValT Default) { - return Default; - } -}; - -template -struct ValueOrDefault< - Properties, PropertyKey, - std::enable_if_t< - sycl::ext::oneapi::experimental::is_property_list_v && - Properties::template has_property()>> { - template static constexpr ValT get(ValT) { - return Properties::template get_property().value; - } -}; -} // namespace detail - // A helper templateless base class to get the host_pipe name. class pipe_base { @@ -100,7 +80,7 @@ class pipe : public pipe_base { const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), false, + CGH.ext_intel_read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), false, true /* read */); }); e.wait(); @@ -128,16 +108,12 @@ class pipe : public pipe_base { const void *data_ptr = &data; event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), + CGH.ext_intel_read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), false, false /* write */); }); e.wait(); - if (e.get_info() == - sycl::info::event_command_status::complete) { - success_code = true; - } else { - success_code = false; - } + success_code = e.get_info() == + sycl::info::event_command_status::complete; } // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V @@ -255,7 +231,7 @@ class pipe : public pipe_base { const void *HostPipePtr = &m_Storage; const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), true, + CGH.ext_intel_read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), true, true /*blocking read */); }); e.wait(); @@ -274,7 +250,7 @@ class pipe : public pipe_base { const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); const void *data_ptr = &data; event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), + CGH.ext_intel_read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), true, false /*blocking write */); }); e.wait(); @@ -379,20 +355,20 @@ class pipe : public pipe_base { static constexpr int32_t m_Capacity = _min_capacity; static constexpr int32_t m_ready_latency = - detail::ValueOrDefault<_propertiesT, + oneapi::experimental::detail::ValueOrDefault<_propertiesT, ready_latency_key>::template get(0); static constexpr int32_t m_bits_per_symbol = - detail::ValueOrDefault<_propertiesT, + oneapi::experimental::detail::ValueOrDefault<_propertiesT, bits_per_symbol_key>::template get(8); static constexpr bool m_uses_valid = - detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get( + oneapi::experimental::detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get( true); static constexpr bool m_first_symbol_in_high_order_bits = - detail::ValueOrDefault< + oneapi::experimental::detail::ValueOrDefault< _propertiesT, first_symbol_in_high_order_bits_key>::template get(0); static constexpr protocol_name m_protocol = - detail::ValueOrDefault<_propertiesT, protocol_key>::template get< + oneapi::experimental::detail::ValueOrDefault<_propertiesT, protocol_key>::template get< protocol_name>(protocol_name::AVALON_STREAMING_USES_READY); public: diff --git a/sycl/include/sycl/ext/oneapi/properties/properties.hpp b/sycl/include/sycl/ext/oneapi/properties/properties.hpp index 5b83abf6cef5a..1604410b41054 100644 --- a/sycl/include/sycl/ext/oneapi/properties/properties.hpp +++ b/sycl/include/sycl/ext/oneapi/properties/properties.hpp @@ -221,6 +221,24 @@ template using merged_properties_t = typename merged_properties::type; +template +struct ValueOrDefault { + template static constexpr ValT get(ValT Default) { + return Default; + } +}; + +template +struct ValueOrDefault< + Properties, PropertyKey, + std::enable_if_t< + is_property_list_v && + Properties::template has_property()>> { + template static constexpr ValT get(ValT) { + return Properties::template get_property().value; + } +}; + } // namespace detail } // namespace ext::oneapi::experimental diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 99091516fa376..ebf5106e46972 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -2652,7 +2652,7 @@ class __SYCL_EXPORT handler { /// expr __pipe member \param Size the size of data getting read back / to. /// /// \param Size the size of data getting read back / to. \param Blocking /// if read/write opeartion is blocking \param Read 1 for read, 0 for write - void read_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, + void ext_intel_read_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, bool Block, bool Read); /// Copies data from a USM memory region to a device_global. diff --git a/sycl/source/detail/pipes.cpp b/sycl/source/detail/pipes.cpp index a3b156a85a0a8..9b8b805a07662 100755 --- a/sycl/source/detail/pipes.cpp +++ b/sycl/source/detail/pipes.cpp @@ -26,4 +26,4 @@ __SYCL_EXPORT std::string pipe_base::get_pipe_name(const void *HostPipePtr) { } // namespace intel } // namespace ext } // __SYCL_INLINE_VER_NAMESPACE(_V1) -} // namespace sycl \ No newline at end of file +} // namespace sycl diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 63bc9ba4f1ef7..82c192470bcc4 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1322,12 +1322,10 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) { // * 8 bytes - Size of the property. // * 4 bytes - Size of the underlying type in the host_pipe. // Note: Property may be padded. - constexpr unsigned int NumPropertySizeBytes = 8; - constexpr unsigned int NumTypeBytes = 4; - assert(HostPipeInfo.size() >= NumPropertySizeBytes + NumTypeBytes && - "Unexpected property size"); - auto TypeSize = *reinterpret_cast( - &HostPipeInfo[NumPropertySizeBytes]); + + HostPipeInfo.dropBytes(8); + auto TypeSize = HostPipeInfo.consume(); + assert(HostPipeInfo.empty() && "Extra data left!"); auto ExistingHostPipe = m_HostPipes.find(HostPipe->Name); if (ExistingHostPipe != m_HostPipes.end()) { diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 6f2aa7fe1796d..85737ab25e640 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -861,7 +861,7 @@ id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) { return id<2>{std::min(ItemLimit[0], Height), std::min(ItemLimit[1], Width)}; } -void handler::read_write_host_pipe(const std::string &Name, void *Ptr, +void handler::ext_intel_read_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, bool Block, bool Read) { MImpl->HostPipeName = Name; MImpl->HostPipePtr = Ptr; diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index f76fd3a8a3db2..f784bf9a39644 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3,7 +3,7 @@ # DO NOT EDIT IT MANUALLY. Refer to sycl/doc/developer/ABIPolicyGuide.md for more info. ################################################################################ -# RUN: env LLVM_BIN_PATH=%llvm_build_bin_dir python %sycl_tools_src_dir/abi_check.py --mode check_symbols --reference %s %sycl_libs_dir/libsycl.so +# RUN: env LLVM_BIN_PATH=%llvm_build_bin_dir %python %sycl_tools_src_dir/abi_check.py --mode check_symbols --reference %s %sycl_libs_dir/libsycl.so # REQUIRES: linux # UNSUPPORTED: libcxx @@ -3966,7 +3966,6 @@ _ZN4sycl3_V17handler19supportsUSMMemset2DEv _ZN4sycl3_V17handler20DisableRangeRoundingEv _ZN4sycl3_V17handler20associateWithHandlerEPNS0_6detail16AccessorBaseHostENS0_6access6targetE _ZN4sycl3_V17handler20memcpyToDeviceGlobalEPKvS3_bmm -_ZN4sycl3_V17handler20read_write_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmbb _ZN4sycl3_V17handler20setStateSpecConstSetEv _ZN4sycl3_V17handler22ext_oneapi_fill2d_implEPvmPKvmmm _ZN4sycl3_V17handler22memcpyFromDeviceGlobalEPvPKvbmm @@ -3979,6 +3978,7 @@ _ZN4sycl3_V17handler24ext_oneapi_memset2d_implEPvmimm _ZN4sycl3_V17handler27computeFallbackKernelBoundsEmm _ZN4sycl3_V17handler28extractArgsAndReqsFromLambdaEPcmPKNS0_6detail19kernel_param_desc_tEb _ZN4sycl3_V17handler28setStateExplicitKernelBundleEv +_ZN4sycl3_V17handler30ext_intel_read_write_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmbb _ZN4sycl3_V17handler6memcpyEPvPKvm _ZN4sycl3_V17handler6memsetEPvim _ZN4sycl3_V17handler7barrierERKSt6vectorINS0_5eventESaIS3_EE diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index 631cbc25bbe00..5600d599b5e63 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -837,6 +837,7 @@ ?end@exception_list@_V1@sycl@@QEBA?AV?$_Vector_const_iterator@V?$_Vector_val@U?$_Simple_types@Vexception_ptr@std@@@std@@@std@@@std@@XZ ?end@kernel_bundle_plain@detail@_V1@sycl@@IEBAPEBVdevice_image_plain@234@XZ ?ext_codeplay_supports_fusion@queue@_V1@sycl@@QEBA_NXZ +?ext_intel_read_write_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N3@Z ?ext_oneapi_barrier@handler@_V1@sycl@@QEAAXAEBV?$vector@Vevent@_V1@sycl@@V?$allocator@Vevent@_V1@sycl@@@std@@@std@@@Z ?ext_oneapi_barrier@handler@_V1@sycl@@QEAAXXZ ?ext_oneapi_empty@queue@_V1@sycl@@QEBA_NXZ @@ -1138,7 +1139,6 @@ ?prefetch_usm@MemoryManager@detail@_V1@sycl@@SAXPEAXV?$shared_ptr@Vqueue_impl@detail@_V1@sycl@@@std@@_KV?$vector@PEAU_pi_event@@V?$allocator@PEAU_pi_event@@@std@@@6@PEAPEAU_pi_event@@@Z ?processArg@handler@_V1@sycl@@AEAAXPEAXAEBW4kernel_param_kind_t@detail@23@H_KAEA_K_N4@Z ?query@tls_code_loc_t@detail@_V1@sycl@@QEAAAEBUcode_location@234@XZ -?read_write_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N3@Z ?reduComputeWGSize@detail@_V1@sycl@@YA_K_K0AEA_K@Z ?reduGetMaxNumConcurrentWorkGroups@detail@_V1@sycl@@YAIV?$shared_ptr@Vqueue_impl@detail@_V1@sycl@@@std@@@Z ?reduGetMaxWGSize@detail@_V1@sycl@@YA_KV?$shared_ptr@Vqueue_impl@detail@_V1@sycl@@@std@@_K@Z diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index e584a1f759321..9541b70c27453 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -135,7 +135,7 @@ TEST_F(PipeTest, Basic) { int host_pipe_read_data; void *data_ptr = &host_pipe_read_data; event e = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, data_ptr, sizeof(int), true, + CGH.ext_intel_read_write_host_pipe(pipe_name, data_ptr, sizeof(int), true, true /* read */); }); e.wait(); @@ -145,7 +145,7 @@ TEST_F(PipeTest, Basic) { int tmp = 9; void *data_ptr2 = &tmp; event e_write = q.submit([=](handler &CGH) { - CGH.read_write_host_pipe(pipe_name, data_ptr2, sizeof(int), true, + CGH.ext_intel_read_write_host_pipe(pipe_name, data_ptr2, sizeof(int), true, false /* write */); }); e_write.wait(); From 1b6db485f32e45038edac8510aedb10b109f5558 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Sun, 26 Mar 2023 12:58:40 -0700 Subject: [PATCH 39/56] Variable naming style change --- .../sycl/ext/intel/experimental/pipes.hpp | 78 +++++++++---------- .../pipes/host_pipe_registration.cpp | 26 +++---- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 78e5520f1af56..54e942688e44b 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -66,37 +66,37 @@ class pipe : public pipe_base { // Non-blocking pipes // Host API - static _dataT read(queue &q, bool &success_code, - memory_order order = memory_order::seq_cst) { - const device Dev = q.get_device(); + static _dataT read(queue &Q, bool &Success, + memory_order Order = memory_order::seq_cst) { + const device Dev = Q.get_device(); bool IsPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); if (!IsPipeSupported) { return _dataT(); } - _dataT data; - void *data_ptr = &data; + _dataT Data; + void *DataPtr = &Data; const void *HostPipePtr = &m_Storage; - const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); + const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); - event e = q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), false, + event E = Q.submit([=](handler &CGH) { + CGH.ext_intel_read_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), false, true /* read */); }); - e.wait(); - if (e.get_info() == + E.wait(); + if (E.get_info() == sycl::info::event_command_status::complete) { - success_code = true; - return *(_dataT *)data_ptr; + Success = true; + return *(_dataT *)DataPtr; } else { - success_code = false; + Success = false; return _dataT(); } } - static void write(queue &q, const _dataT &data, bool &success_code, - memory_order order = memory_order::seq_cst) { - const device Dev = q.get_device(); + static void write(queue &Q, const _dataT &Data, bool &Success, + memory_order Order = memory_order::seq_cst) { + const device Dev = Q.get_device(); bool IsPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); if (!IsPipeSupported) { @@ -104,15 +104,15 @@ class pipe : public pipe_base { } const void *HostPipePtr = &m_Storage; - const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); - const void *data_ptr = &data; + const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); + const void *DataPtr = &Data; - event e = q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), + event E = Q.submit([=](handler &CGH) { + CGH.ext_intel_read_write_host_pipe(PipeName, (void *)DataPtr, sizeof(_dataT), false, false /* write */); }); - e.wait(); - success_code = e.get_info() == + E.wait(); + Success = E.get_info() == sycl::info::event_command_status::complete; } @@ -219,41 +219,41 @@ class pipe : public pipe_base { // Blocking pipes // Host API - static _dataT read(queue &q, memory_order order = memory_order::seq_cst) { - const device Dev = q.get_device(); + static _dataT read(queue &Q, memory_order Order = memory_order::seq_cst) { + const device Dev = Q.get_device(); bool IsPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); if (!IsPipeSupported) { return _dataT(); } - _dataT data; - void *data_ptr = &data; + _dataT Data; + void *DataPtr = &Data; const void *HostPipePtr = &m_Storage; - const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); - event e = q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(pipe_name, data_ptr, sizeof(_dataT), true, + const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); + event E = Q.submit([=](handler &CGH) { + CGH.ext_intel_read_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), true, true /*blocking read */); }); - e.wait(); - return *(_dataT *)data_ptr; + E.wait(); + return *(_dataT *)DataPtr; } - static void write(queue &q, const _dataT &data, - memory_order order = memory_order::seq_cst) { - const device Dev = q.get_device(); + static void write(queue &Q, const _dataT &Data, + memory_order Order = memory_order::seq_cst) { + const device Dev = Q.get_device(); bool IsPipeSupported = Dev.has_extension("cl_intel_program_scope_host_pipe"); if (!IsPipeSupported) { return; } const void *HostPipePtr = &m_Storage; - const std::string pipe_name = pipe_base::get_pipe_name(HostPipePtr); - const void *data_ptr = &data; - event e = q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(pipe_name, (void *)data_ptr, sizeof(_dataT), + const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); + const void *DataPtr = &Data; + event E = Q.submit([=](handler &CGH) { + CGH.ext_intel_read_write_host_pipe(PipeName, (void *)DataPtr, sizeof(_dataT), true, false /*blocking write */); }); - e.wait(); + E.wait(); } // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 9541b70c27453..51725755bb9bf 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -127,27 +127,27 @@ TEST_F(PipeTest, Basic) { // Get the hostpipe const void *HostPipePtr = Pipe::get_host_ptr(); - detail::HostPipeMapEntry *hostPipeEntry = + detail::HostPipeMapEntry *HostPipeEntry = detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); - const std::string pipe_name = hostPipeEntry->MUniqueId; + const std::string PipeName = HostPipeEntry->MUniqueId; // Testing read - int host_pipe_read_data; - void *data_ptr = &host_pipe_read_data; - event e = q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(pipe_name, data_ptr, sizeof(int), true, + int HostPipeReadData; + void *DataPtrRead = &HostPipeReadData; + event ERead = q.submit([=](handler &CGH) { + CGH.ext_intel_read_write_host_pipe(PipeName, DataPtrRead, sizeof(int), true, true /* read */); }); - e.wait(); - assert(host_pipe_read_data == PipeReadVal); + ERead.wait(); + assert(HostPipeReadData == PipeReadVal); // Testing write - int tmp = 9; - void *data_ptr2 = &tmp; - event e_write = q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(pipe_name, data_ptr2, sizeof(int), true, + int HostPipeWriteData = 9; + void *DataPtrWrite = &HostPipeWriteData; + event EWrite = q.submit([=](handler &CGH) { + CGH.ext_intel_read_write_host_pipe(PipeName, DataPtrWrite, sizeof(int), true, false /* write */); }); - e_write.wait(); + EWrite.wait(); assert(PipeWriteVal == 9); } From 2c6f27de22b9e36bbead69eff0242621bc92563b Mon Sep 17 00:00:00 2001 From: "Ho, Robert" Date: Mon, 27 Mar 2023 09:08:32 -0700 Subject: [PATCH 40/56] Reuse unique id attribute function from device globals for host pipes --- llvm/include/llvm/SYCLLowerIR/HostPipes.h | 8 -------- llvm/lib/SYCLLowerIR/DeviceGlobals.cpp | 10 +++++----- llvm/lib/SYCLLowerIR/HostPipes.cpp | 21 ++------------------- 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/llvm/include/llvm/SYCLLowerIR/HostPipes.h b/llvm/include/llvm/SYCLLowerIR/HostPipes.h index a243fc029c90a..9942a99187c3b 100644 --- a/llvm/include/llvm/SYCLLowerIR/HostPipes.h +++ b/llvm/include/llvm/SYCLLowerIR/HostPipes.h @@ -56,12 +56,4 @@ bool isHostPipeVariable(const GlobalVariable &GV); /// map. HostPipePropertyMapTy collectHostPipeProperties(const Module &M); -/// Returns the unique id for the host pipe variable. -/// -/// @param GV [in] Device Global variable. -/// -/// @returns the unique id of the host pipe variable represented -/// in the LLVM IR by \c GV. -StringRef getHostPipeVariableUniqueId(const GlobalVariable &GV); - } // end namespace llvm diff --git a/llvm/lib/SYCLLowerIR/DeviceGlobals.cpp b/llvm/lib/SYCLLowerIR/DeviceGlobals.cpp index b28f0d63f8cbd..a48adfdcb34a8 100644 --- a/llvm/lib/SYCLLowerIR/DeviceGlobals.cpp +++ b/llvm/lib/SYCLLowerIR/DeviceGlobals.cpp @@ -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(); } diff --git a/llvm/lib/SYCLLowerIR/HostPipes.cpp b/llvm/lib/SYCLLowerIR/HostPipes.cpp index 95b243e2c9447..ca116c702c1d4 100644 --- a/llvm/lib/SYCLLowerIR/HostPipes.cpp +++ b/llvm/lib/SYCLLowerIR/HostPipes.cpp @@ -1,4 +1,4 @@ -//===----- HostPipes.cpp - SYCL Device Globals Pass -------------------===// +//===------------- 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. @@ -24,7 +24,6 @@ namespace { constexpr StringRef SYCL_HOST_PIPE_ATTR = "sycl-host-pipe"; constexpr StringRef SYCL_HOST_PIPE_SIZE_ATTR = "sycl-host-pipe-size"; -constexpr StringRef SYCL_UNIQUE_ID_ATTR = "sycl-unique-id"; /// Returns the size (in bytes) of the type \c T of the host /// pipe variable. @@ -60,22 +59,6 @@ bool isHostPipeVariable(const GlobalVariable &GV) { return GV.hasAttribute(SYCL_HOST_PIPE_ATTR); } -/// Returns the unique id for the host pipe variable. -/// -/// The function gets this value from the LLVM IR attribute \c -/// sycl-unique-id. -/// -/// @param GV [in] Device Global variable. -/// -/// @returns the unique id of the host pipe variable represented -/// in the LLVM IR by \c GV. -StringRef getHostPipeVariableUniqueId(const GlobalVariable &GV) { - assert(GV.hasAttribute(SYCL_UNIQUE_ID_ATTR) && - "a 'sycl-unique-id' string must be associated with every host " - "pipe variable"); - return GV.getAttribute(SYCL_UNIQUE_ID_ATTR).getValueAsString(); -} - HostPipePropertyMapTy collectHostPipeProperties(const Module &M) { HostPipePropertyMapTy HPM; auto HostPipeNum = count_if(M.globals(), isHostPipeVariable); @@ -88,7 +71,7 @@ HostPipePropertyMapTy collectHostPipeProperties(const Module &M) { if (!isHostPipeVariable(GV)) continue; - HPM[getHostPipeVariableUniqueId(GV)] = {getHostPipeTypeSize(GV)}; + HPM[getGlobalVariableUniqueId(GV)] = {getHostPipeTypeSize(GV)}; } return HPM; From 3a49068345aa848960094dd4509a294b2a791e9b Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Mon, 27 Mar 2023 10:57:33 -0700 Subject: [PATCH 41/56] Update PI version and run clang format --- sycl/include/sycl/detail/pi.h | 3 +- .../sycl/ext/intel/experimental/pipes.hpp | 49 ++++++++++--------- sycl/include/sycl/ext/intel/pipes.hpp | 24 ++++++--- .../sycl/ext/oneapi/properties/properties.hpp | 5 +- sycl/include/sycl/handler.hpp | 4 +- .../program_manager/program_manager.cpp | 2 +- sycl/source/handler.cpp | 3 +- .../pipes/host_pipe_registration.cpp | 6 +-- 8 files changed, 55 insertions(+), 41 deletions(-) diff --git a/sycl/include/sycl/detail/pi.h b/sycl/include/sycl/detail/pi.h index 50976bbc236d0..f606f46fa4f32 100644 --- a/sycl/include/sycl/detail/pi.h +++ b/sycl/include/sycl/detail/pi.h @@ -77,9 +77,10 @@ // 12.22 Add piGetDeviceAndHostTimer to query device wall-clock timestamp // 12.23 Added new piextEnqueueDeviceGlobalVariableWrite and // piextEnqueueDeviceGlobalVariableRead functions. +// 12.24 Added piextEnqueueReadHostPipe and piextEnqueueWriteHostPipe functions. #define _PI_H_VERSION_MAJOR 12 -#define _PI_H_VERSION_MINOR 23 +#define _PI_H_VERSION_MINOR 24 #define _PI_STRING_HELPER(a) #a #define _PI_CONCAT(a, b) _PI_STRING_HELPER(a.b) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 54e942688e44b..ab5bba95b672e 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -80,8 +80,8 @@ class pipe : public pipe_base { const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); event E = Q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), false, - true /* read */); + CGH.ext_intel_read_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), + false, true /* read */); }); E.wait(); if (E.get_info() == @@ -108,12 +108,12 @@ class pipe : public pipe_base { const void *DataPtr = &Data; event E = Q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, (void *)DataPtr, sizeof(_dataT), - false, false /* write */); + CGH.ext_intel_read_write_host_pipe( + PipeName, (void *)DataPtr, sizeof(_dataT), false, false /* write */); }); E.wait(); Success = E.get_info() == - sycl::info::event_command_status::complete; + sycl::info::event_command_status::complete; } // Reading from pipe is lowered to SPIR-V instruction OpReadPipe via SPIR-V @@ -157,7 +157,8 @@ class pipe : public pipe_base { (void)Properties; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -206,7 +207,8 @@ class pipe : public pipe_base { (void)Properties; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -231,8 +233,8 @@ class pipe : public pipe_base { const void *HostPipePtr = &m_Storage; const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); event E = Q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), true, - true /*blocking read */); + CGH.ext_intel_read_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), + true, true /*blocking read */); }); E.wait(); return *(_dataT *)DataPtr; @@ -250,8 +252,9 @@ class pipe : public pipe_base { const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); const void *DataPtr = &Data; event E = Q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, (void *)DataPtr, sizeof(_dataT), - true, false /*blocking write */); + CGH.ext_intel_read_write_host_pipe(PipeName, (void *)DataPtr, + sizeof(_dataT), true, + false /*blocking write */); }); E.wait(); } @@ -296,7 +299,8 @@ class pipe : public pipe_base { (void)Properties; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -341,7 +345,8 @@ class pipe : public pipe_base { (void)Properties; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -355,21 +360,21 @@ class pipe : public pipe_base { static constexpr int32_t m_Capacity = _min_capacity; static constexpr int32_t m_ready_latency = - oneapi::experimental::detail::ValueOrDefault<_propertiesT, - ready_latency_key>::template get(0); + oneapi::experimental::detail::ValueOrDefault< + _propertiesT, ready_latency_key>::template get(0); static constexpr int32_t m_bits_per_symbol = - oneapi::experimental::detail::ValueOrDefault<_propertiesT, - bits_per_symbol_key>::template get(8); + oneapi::experimental::detail::ValueOrDefault< + _propertiesT, bits_per_symbol_key>::template get(8); static constexpr bool m_uses_valid = - oneapi::experimental::detail::ValueOrDefault<_propertiesT, uses_valid_key>::template get( - true); + oneapi::experimental::detail::ValueOrDefault< + _propertiesT, uses_valid_key>::template get(true); static constexpr bool m_first_symbol_in_high_order_bits = oneapi::experimental::detail::ValueOrDefault< _propertiesT, first_symbol_in_high_order_bits_key>::template get(0); - static constexpr protocol_name m_protocol = - oneapi::experimental::detail::ValueOrDefault<_propertiesT, protocol_key>::template get< - protocol_name>(protocol_name::AVALON_STREAMING_USES_READY); + static constexpr protocol_name m_protocol = oneapi::experimental::detail:: + ValueOrDefault<_propertiesT, protocol_key>::template get( + protocol_name::AVALON_STREAMING_USES_READY); public: static constexpr struct ConstantPipeStorageExp m_Storage = { diff --git a/sycl/include/sycl/ext/intel/pipes.hpp b/sycl/include/sycl/ext/intel/pipes.hpp index 72d1a358c8bb7..8b8dffeba04f4 100644 --- a/sycl/include/sycl/ext/intel/pipes.hpp +++ b/sycl/include/sycl/ext/intel/pipes.hpp @@ -35,7 +35,8 @@ template class pipe { (void)_Success; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -52,7 +53,8 @@ template class pipe { (void)_Data; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -69,7 +71,8 @@ template class pipe { #else throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead.."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead.."); #endif // __SYCL_DEVICE_ONLY__ } @@ -84,7 +87,8 @@ template class pipe { (void)_Data; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -137,7 +141,8 @@ class kernel_readable_io_pipe { (void)_Success; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -154,7 +159,8 @@ class kernel_readable_io_pipe { #else throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -187,7 +193,8 @@ class kernel_writeable_io_pipe { (void)_Success; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } @@ -203,7 +210,8 @@ class kernel_writeable_io_pipe { (void)_Data; throw sycl::exception( sycl::make_error_code(sycl::errc::feature_not_supported), - "Device-side API are not supported on a host device. Please use host-side API instead."); + "Device-side API are not supported on a host device. Please use " + "host-side API instead."); #endif // __SYCL_DEVICE_ONLY__ } diff --git a/sycl/include/sycl/ext/oneapi/properties/properties.hpp b/sycl/include/sycl/ext/oneapi/properties/properties.hpp index 1604410b41054..9cb851a639a21 100644 --- a/sycl/include/sycl/ext/oneapi/properties/properties.hpp +++ b/sycl/include/sycl/ext/oneapi/properties/properties.hpp @@ -231,9 +231,8 @@ struct ValueOrDefault { template struct ValueOrDefault< Properties, PropertyKey, - std::enable_if_t< - is_property_list_v && - Properties::template has_property()>> { + std::enable_if_t && + Properties::template has_property()>> { template static constexpr ValT get(ValT) { return Properties::template get_property().value; } diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index ebf5106e46972..aba45421dec7e 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -2652,8 +2652,8 @@ class __SYCL_EXPORT handler { /// expr __pipe member \param Size the size of data getting read back / to. /// /// \param Size the size of data getting read back / to. \param Blocking /// if read/write opeartion is blocking \param Read 1 for read, 0 for write - void ext_intel_read_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, - bool Block, bool Read); + void ext_intel_read_write_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block, bool Read); /// Copies data from a USM memory region to a device_global. /// Throws an exception if the copy operation intends to write outside the diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 82c192470bcc4..7e6b3e9f1f736 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1322,7 +1322,7 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) { // * 8 bytes - Size of the property. // * 4 bytes - Size of the underlying type in the host_pipe. // Note: Property may be padded. - + HostPipeInfo.dropBytes(8); auto TypeSize = HostPipeInfo.consume(); assert(HostPipeInfo.empty() && "Extra data left!"); diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 85737ab25e640..84919136bd670 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -862,7 +862,8 @@ id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) { } void handler::ext_intel_read_write_host_pipe(const std::string &Name, void *Ptr, - size_t Size, bool Block, bool Read) { + size_t Size, bool Block, + bool Read) { MImpl->HostPipeName = Name; MImpl->HostPipePtr = Ptr; MImpl->HostPipeTypeSize = Size; diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 51725755bb9bf..3b79729eb77a8 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -136,7 +136,7 @@ TEST_F(PipeTest, Basic) { void *DataPtrRead = &HostPipeReadData; event ERead = q.submit([=](handler &CGH) { CGH.ext_intel_read_write_host_pipe(PipeName, DataPtrRead, sizeof(int), true, - true /* read */); + true /* read */); }); ERead.wait(); assert(HostPipeReadData == PipeReadVal); @@ -145,8 +145,8 @@ TEST_F(PipeTest, Basic) { int HostPipeWriteData = 9; void *DataPtrWrite = &HostPipeWriteData; event EWrite = q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, DataPtrWrite, sizeof(int), true, - false /* write */); + CGH.ext_intel_read_write_host_pipe(PipeName, DataPtrWrite, sizeof(int), + true, false /* write */); }); EWrite.wait(); assert(PipeWriteVal == 9); From a3399561786f98c511bd63be6b26e8aff0e8bedc Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Mon, 27 Mar 2023 11:54:11 -0700 Subject: [PATCH 42/56] clang-format change --- llvm/lib/SYCLLowerIR/DeviceGlobals.cpp | 2 +- sycl/source/detail/handler_impl.hpp | 1 - sycl/source/handler.cpp | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/llvm/lib/SYCLLowerIR/DeviceGlobals.cpp b/llvm/lib/SYCLLowerIR/DeviceGlobals.cpp index a48adfdcb34a8..2dd2bb0560552 100644 --- a/llvm/lib/SYCLLowerIR/DeviceGlobals.cpp +++ b/llvm/lib/SYCLLowerIR/DeviceGlobals.cpp @@ -79,7 +79,7 @@ bool hasDeviceImageScopeProperty(const GlobalVariable &GV) { /// /// @param GV [in] Device Global or Hostpipe variable. /// -/// @returns the unique id of the device global or hostpipe variable +/// @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) && diff --git a/sycl/source/detail/handler_impl.hpp b/sycl/source/detail/handler_impl.hpp index 1a24889639238..3cb23c1df8d54 100644 --- a/sycl/source/detail/handler_impl.hpp +++ b/sycl/source/detail/handler_impl.hpp @@ -100,7 +100,6 @@ class handler_impl { RT::PiKernelCacheConfig MKernelCacheConfig = PI_EXT_KERNEL_EXEC_INFO_CACHE_DEFAULT; - }; } // namespace detail diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index d4861a36692d2..1a5765f1daf78 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -903,8 +903,7 @@ handler::getContextImplPtr() const { return MQueue->getContextImplPtr(); } -void handler::setKernelCacheConfig( - detail::RT::PiKernelCacheConfig Config) { +void handler::setKernelCacheConfig(detail::RT::PiKernelCacheConfig Config) { MImpl->MKernelCacheConfig = Config; } From 80c57d5fdf5408b686191e82f1a98ecdd3098889 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 28 Mar 2023 11:34:12 -0700 Subject: [PATCH 43/56] seperate handler function into read and write functions --- .../sycl/ext/intel/experimental/pipes.hpp | 16 +++++++------- sycl/include/sycl/handler.hpp | 21 +++++++++++++------ sycl/source/handler.cpp | 17 +++++++++++---- sycl/test/abi/sycl_symbols_linux.dump | 3 ++- sycl/test/abi/sycl_symbols_windows.dump | 3 ++- .../pipes/host_pipe_registration.cpp | 6 ++---- 6 files changed, 41 insertions(+), 25 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index ab5bba95b672e..debce8e1a57fd 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -80,8 +80,7 @@ class pipe : public pipe_base { const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); event E = Q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), - false, true /* read */); + CGH.ext_intel_read_host_pipe(PipeName, DataPtr, sizeof(_dataT) /* non-blocking */); }); E.wait(); if (E.get_info() == @@ -108,8 +107,8 @@ class pipe : public pipe_base { const void *DataPtr = &Data; event E = Q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe( - PipeName, (void *)DataPtr, sizeof(_dataT), false, false /* write */); + CGH.ext_intel_write_host_pipe( + PipeName, (void *)DataPtr, sizeof(_dataT) /* non-blocking */); }); E.wait(); Success = E.get_info() == @@ -233,8 +232,8 @@ class pipe : public pipe_base { const void *HostPipePtr = &m_Storage; const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); event E = Q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), - true, true /*blocking read */); + CGH.ext_intel_read_host_pipe(PipeName, DataPtr, sizeof(_dataT), + true /*blocking*/); }); E.wait(); return *(_dataT *)DataPtr; @@ -252,9 +251,8 @@ class pipe : public pipe_base { const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); const void *DataPtr = &Data; event E = Q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, (void *)DataPtr, - sizeof(_dataT), true, - false /*blocking write */); + CGH.ext_intel_write_host_pipe(PipeName, (void *)DataPtr, + sizeof(_dataT), true /*blocking */); }); E.wait(); } diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 1a02097c6ac91..4497845f9c6b9 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -2700,14 +2700,23 @@ class __SYCL_EXPORT handler { else commonUSMFill2DFallbackKernel(Dest, DestPitch, Pattern, Width, Height); } - /// Read from or write to host pipes given a host address and + /// Read from a host pipe given a host address and /// \param Name name of the host pipe to be passed into lower level runtime /// \param Ptr host pointer of host pipe as identified by address of its const - /// expr __pipe member \param Size the size of data getting read back / to. - /// /// \param Size the size of data getting read back / to. \param Blocking - /// if read/write opeartion is blocking \param Read 1 for read, 0 for write - void ext_intel_read_write_host_pipe(const std::string &Name, void *Ptr, - size_t Size, bool Block, bool Read); + /// expr m_Storage member \param Size the size of data getting read back / to. + /// /// \param Size the size of data getting read back / to. \param Block + /// if read opeartion is blocking, default to false. + void ext_intel_read_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block=false); + + /// Write to host pipes given a host address and + /// \param Name name of the host pipe to be passed into lower level runtime + /// \param Ptr host pointer of host pipe as identified by address of its const + /// expr m_Storage member \param Size the size of data getting read back / to. + /// /// \param Size the size of data write / to. \param Block + /// if write opeartion is blocking, default to false. + void ext_intel_write_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block=false); /// Copies data from a USM memory region to a device_global. /// Throws an exception if the copy operation intends to write outside the diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 1a5765f1daf78..3a44c5e810011 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -863,14 +863,23 @@ id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) { return id<2>{std::min(ItemLimit[0], Height), std::min(ItemLimit[1], Width)}; } -void handler::ext_intel_read_write_host_pipe(const std::string &Name, void *Ptr, - size_t Size, bool Block, - bool Read) { +void handler::ext_intel_read_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block) { MImpl->HostPipeName = Name; MImpl->HostPipePtr = Ptr; MImpl->HostPipeTypeSize = Size; MImpl->HostPipeBlocking = Block; - MImpl->HostPipeRead = Read; + MImpl->HostPipeRead = 1; + setType(detail::CG::ReadWriteHostPipe); +} + +void handler::ext_intel_write_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block) { + MImpl->HostPipeName = Name; + MImpl->HostPipePtr = Ptr; + MImpl->HostPipeTypeSize = Size; + MImpl->HostPipeBlocking = Block; + MImpl->HostPipeRead = 0; setType(detail::CG::ReadWriteHostPipe); } diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index d2f3f8b033638..8b12210d02882 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3979,7 +3979,8 @@ _ZN4sycl3_V17handler24ext_oneapi_memset2d_implEPvmimm _ZN4sycl3_V17handler27computeFallbackKernelBoundsEmm _ZN4sycl3_V17handler28extractArgsAndReqsFromLambdaEPcmPKNS0_6detail19kernel_param_desc_tEb _ZN4sycl3_V17handler28setStateExplicitKernelBundleEv -_ZN4sycl3_V17handler30ext_intel_read_write_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmbb +_ZN4sycl3_V17handler30ext_intel_read_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmbb +_ZN4sycl3_V17handler30ext_intel_write_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmbb _ZN4sycl3_V17handler6memcpyEPvPKvm _ZN4sycl3_V17handler6memsetEPvim _ZN4sycl3_V17handler7barrierERKSt6vectorINS0_5eventESaIS3_EE diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index d2338b63efe23..4adf7cd9efb7a 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -838,7 +838,8 @@ ?end@exception_list@_V1@sycl@@QEBA?AV?$_Vector_const_iterator@V?$_Vector_val@U?$_Simple_types@Vexception_ptr@std@@@std@@@std@@@std@@XZ ?end@kernel_bundle_plain@detail@_V1@sycl@@IEBAPEBVdevice_image_plain@234@XZ ?ext_codeplay_supports_fusion@queue@_V1@sycl@@QEBA_NXZ -?ext_intel_read_write_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N3@Z +?ext_intel_read_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N3@Z +?ext_intel_write_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N3@Z ?ext_oneapi_barrier@handler@_V1@sycl@@QEAAXAEBV?$vector@Vevent@_V1@sycl@@V?$allocator@Vevent@_V1@sycl@@@std@@@std@@@Z ?ext_oneapi_barrier@handler@_V1@sycl@@QEAAXXZ ?ext_oneapi_empty@queue@_V1@sycl@@QEBA_NXZ diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 3b79729eb77a8..b810a774f3ccb 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -135,8 +135,7 @@ TEST_F(PipeTest, Basic) { int HostPipeReadData; void *DataPtrRead = &HostPipeReadData; event ERead = q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, DataPtrRead, sizeof(int), true, - true /* read */); + CGH.ext_intel_read_host_pipe(PipeName, DataPtrRead, sizeof(int), true /* blocking */); }); ERead.wait(); assert(HostPipeReadData == PipeReadVal); @@ -145,8 +144,7 @@ TEST_F(PipeTest, Basic) { int HostPipeWriteData = 9; void *DataPtrWrite = &HostPipeWriteData; event EWrite = q.submit([=](handler &CGH) { - CGH.ext_intel_read_write_host_pipe(PipeName, DataPtrWrite, sizeof(int), - true, false /* write */); + CGH.ext_intel_write_host_pipe(PipeName, DataPtrWrite, sizeof(int), true/* blocking */); }); EWrite.wait(); assert(PipeWriteVal == 9); From 3c2ed1cdc641ce12a8b59c791b1ffe47c92f8e3b Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 28 Mar 2023 14:42:26 -0700 Subject: [PATCH 44/56] make the new handler member private --- sycl/include/sycl/handler.hpp | 48 ++++++++++++++++--------- sycl/test/abi/sycl_symbols_linux.dump | 6 ++-- sycl/test/abi/sycl_symbols_windows.dump | 4 +-- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 4497845f9c6b9..4d234ab9c06d3 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -95,6 +95,14 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { class handler; template class buffer; + +namespace ext::intel::experimental +{ + template + class pipe; +} + namespace detail { class handler_impl; @@ -2700,23 +2708,6 @@ class __SYCL_EXPORT handler { else commonUSMFill2DFallbackKernel(Dest, DestPitch, Pattern, Width, Height); } - /// Read from a host pipe given a host address and - /// \param Name name of the host pipe to be passed into lower level runtime - /// \param Ptr host pointer of host pipe as identified by address of its const - /// expr m_Storage member \param Size the size of data getting read back / to. - /// /// \param Size the size of data getting read back / to. \param Block - /// if read opeartion is blocking, default to false. - void ext_intel_read_host_pipe(const std::string &Name, void *Ptr, - size_t Size, bool Block=false); - - /// Write to host pipes given a host address and - /// \param Name name of the host pipe to be passed into lower level runtime - /// \param Ptr host pointer of host pipe as identified by address of its const - /// expr m_Storage member \param Size the size of data getting read back / to. - /// /// \param Size the size of data write / to. \param Block - /// if write opeartion is blocking, default to false. - void ext_intel_write_host_pipe(const std::string &Name, void *Ptr, - size_t Size, bool Block=false); /// Copies data from a USM memory region to a device_global. /// Throws an exception if the copy operation intends to write outside the @@ -2905,6 +2896,29 @@ class __SYCL_EXPORT handler { friend class ::MockHandler; friend class detail::queue_impl; + // Make pipe class friend to be able to call ext_intel_read/write_host_pipe method. + template + friend class ext::intel::experimental::pipe; + + /// Read from a host pipe given a host address and + /// \param Name name of the host pipe to be passed into lower level runtime + /// \param Ptr host pointer of host pipe as identified by address of its const + /// expr m_Storage member \param Size the size of data getting read back / to. + /// /// \param Size the size of data getting read back / to. \param Block + /// if read opeartion is blocking, default to false. + void ext_intel_read_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block=false); + + /// Write to host pipes given a host address and + /// \param Name name of the host pipe to be passed into lower level runtime + /// \param Ptr host pointer of host pipe as identified by address of its const + /// expr m_Storage member \param Size the size of data getting read back / to. + /// /// \param Size the size of data write / to. \param Block + /// if write opeartion is blocking, default to false. + void ext_intel_write_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block=false); + bool DisableRangeRounding(); bool RangeRoundingTrace(); diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 8b12210d02882..72471ad897526 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3966,21 +3966,21 @@ _ZN4sycl3_V17handler19supportsUSMMemset2DEv _ZN4sycl3_V17handler20DisableRangeRoundingEv _ZN4sycl3_V17handler20associateWithHandlerEPNS0_6detail16AccessorBaseHostENS0_6access6targetE _ZN4sycl3_V17handler20memcpyToDeviceGlobalEPKvS3_bmm +_ZN4sycl3_V17handler20setKernelCacheConfigE23_pi_kernel_cache_config _ZN4sycl3_V17handler20setStateSpecConstSetEv _ZN4sycl3_V17handler22ext_oneapi_fill2d_implEPvmPKvmmm _ZN4sycl3_V17handler22memcpyFromDeviceGlobalEPvPKvbmm _ZN4sycl3_V17handler22setHandlerKernelBundleENS0_6kernelE _ZN4sycl3_V17handler22setHandlerKernelBundleERKSt10shared_ptrINS0_6detail18kernel_bundle_implEE _ZN4sycl3_V17handler22verifyUsedKernelBundleERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE -_ZN4sycl3_V17handler20setKernelCacheConfigE23_pi_kernel_cache_config _ZN4sycl3_V17handler24GetRangeRoundingSettingsERmS2_S2_ +_ZN4sycl3_V17handler24ext_intel_read_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmb _ZN4sycl3_V17handler24ext_oneapi_memcpy2d_implEPvmPKvmmm _ZN4sycl3_V17handler24ext_oneapi_memset2d_implEPvmimm +_ZN4sycl3_V17handler25ext_intel_write_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmb _ZN4sycl3_V17handler27computeFallbackKernelBoundsEmm _ZN4sycl3_V17handler28extractArgsAndReqsFromLambdaEPcmPKNS0_6detail19kernel_param_desc_tEb _ZN4sycl3_V17handler28setStateExplicitKernelBundleEv -_ZN4sycl3_V17handler30ext_intel_read_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmbb -_ZN4sycl3_V17handler30ext_intel_write_host_pipeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPvmbb _ZN4sycl3_V17handler6memcpyEPvPKvm _ZN4sycl3_V17handler6memsetEPvim _ZN4sycl3_V17handler7barrierERKSt6vectorINS0_5eventESaIS3_EE diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index 4adf7cd9efb7a..4b962de979785 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -838,8 +838,8 @@ ?end@exception_list@_V1@sycl@@QEBA?AV?$_Vector_const_iterator@V?$_Vector_val@U?$_Simple_types@Vexception_ptr@std@@@std@@@std@@@std@@XZ ?end@kernel_bundle_plain@detail@_V1@sycl@@IEBAPEBVdevice_image_plain@234@XZ ?ext_codeplay_supports_fusion@queue@_V1@sycl@@QEBA_NXZ -?ext_intel_read_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N3@Z -?ext_intel_write_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N3@Z +?ext_intel_read_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N@Z +?ext_intel_write_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N@Z ?ext_oneapi_barrier@handler@_V1@sycl@@QEAAXAEBV?$vector@Vevent@_V1@sycl@@V?$allocator@Vevent@_V1@sycl@@@std@@@std@@@Z ?ext_oneapi_barrier@handler@_V1@sycl@@QEAAXXZ ?ext_oneapi_empty@queue@_V1@sycl@@QEBA_NXZ From 66a6307e8262f8edc2c5debbf46981a22ae55292 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Tue, 28 Mar 2023 19:24:20 -0700 Subject: [PATCH 45/56] Fix Pipe unit test to be able access private handler function --- sycl/include/sycl/handler.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 4d234ab9c06d3..6417ff77c9771 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -86,6 +86,7 @@ class __copyAcc2Acc; // For unit testing purposes class MockHandler; +class PipeTest_Basic_Test; namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { @@ -2900,6 +2901,7 @@ class __SYCL_EXPORT handler { template friend class ext::intel::experimental::pipe; + friend class ::PipeTest_Basic_Test; /// Read from a host pipe given a host address and /// \param Name name of the host pipe to be passed into lower level runtime From a9c58f66220d9f8f81de5d10bddeecbdfc30c802 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 06:18:44 -0700 Subject: [PATCH 46/56] fix windows symbol dump --- sycl/test/abi/sycl_symbols_windows.dump | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index 3d48410fa94a9..56559c8fdba87 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -842,8 +842,8 @@ ?end@exception_list@_V1@sycl@@QEBA?AV?$_Vector_const_iterator@V?$_Vector_val@U?$_Simple_types@Vexception_ptr@std@@@std@@@std@@@std@@XZ ?end@kernel_bundle_plain@detail@_V1@sycl@@IEBAPEBVdevice_image_plain@234@XZ ?ext_codeplay_supports_fusion@queue@_V1@sycl@@QEBA_NXZ -?ext_intel_read_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N@Z -?ext_intel_write_host_pipe@handler@_V1@sycl@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N@Z +?ext_intel_read_host_pipe@handler@_V1@sycl@@AEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N@Z +?ext_intel_write_host_pipe@handler@_V1@sycl@@AEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAX_K_N@Z ?ext_oneapi_barrier@handler@_V1@sycl@@QEAAXAEBV?$vector@Vevent@_V1@sycl@@V?$allocator@Vevent@_V1@sycl@@@std@@@std@@@Z ?ext_oneapi_barrier@handler@_V1@sycl@@QEAAXXZ ?ext_oneapi_empty@queue@_V1@sycl@@QEBA_NXZ From e4ff9a455ae35cfd8f4367865e87d0556c5bbf6e Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 09:00:34 -0700 Subject: [PATCH 47/56] fix unit test to call pipe read/write directly --- sycl/include/sycl/handler.hpp | 2 - .../pipes/host_pipe_registration.cpp | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 6417ff77c9771..4d234ab9c06d3 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -86,7 +86,6 @@ class __copyAcc2Acc; // For unit testing purposes class MockHandler; -class PipeTest_Basic_Test; namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { @@ -2901,7 +2900,6 @@ class __SYCL_EXPORT handler { template friend class ext::intel::experimental::pipe; - friend class ::PipeTest_Basic_Test; /// Read from a host pipe given a host address and /// \param Name name of the host pipe to be passed into lower level runtime diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index b810a774f3ccb..afd7506b982ac 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -91,6 +91,26 @@ pi_result redefinedEnqueueWriteHostPipe(pi_queue, pi_program, const char *, return PI_SUCCESS; } +pi_result after_piDeviceGetInfo(pi_device device, pi_device_info param_name, + size_t param_value_size, void *param_value, + size_t *param_value_size_ret) { + constexpr char MockSupportedExtensions[] = + "cl_khr_fp64 cl_khr_fp16 cl_khr_il_program cl_intel_program_scope_host_pipe"; + switch (param_name) { + case PI_DEVICE_INFO_EXTENSIONS: { + if (param_value) { + assert(param_value_size >= sizeof(MockSupportedExtensions)); + std::memcpy(param_value, MockSupportedExtensions, + sizeof(MockSupportedExtensions)); + } + if (param_value_size_ret) + *param_value_size_ret = sizeof(MockSupportedExtensions); + return PI_SUCCESS; + } + } + return PI_SUCCESS; +} + void preparePiMock(unittest::PiMock &Mock) { Mock.redefine( redefinedEnqueueReadHostPipe); @@ -120,32 +140,20 @@ class PipeTest : public ::testing::Test { }; TEST_F(PipeTest, Basic) { + // Fake extension + Mock.redefineAfter(after_piDeviceGetInfo); // Device registration static sycl::unittest::PiImage Img = generateDefaultImage(); static sycl::unittest::PiImageArray<1> ImgArray{&Img}; - // Get the hostpipe - const void *HostPipePtr = Pipe::get_host_ptr(); - detail::HostPipeMapEntry *HostPipeEntry = - detail::ProgramManager::getInstance().getHostPipeEntry(HostPipePtr); - const std::string PipeName = HostPipeEntry->MUniqueId; - - // Testing read + //Testing read int HostPipeReadData; - void *DataPtrRead = &HostPipeReadData; - event ERead = q.submit([=](handler &CGH) { - CGH.ext_intel_read_host_pipe(PipeName, DataPtrRead, sizeof(int), true /* blocking */); - }); - ERead.wait(); + HostPipeReadData = Pipe::read(q); assert(HostPipeReadData == PipeReadVal); // Testing write int HostPipeWriteData = 9; - void *DataPtrWrite = &HostPipeWriteData; - event EWrite = q.submit([=](handler &CGH) { - CGH.ext_intel_write_host_pipe(PipeName, DataPtrWrite, sizeof(int), true/* blocking */); - }); - EWrite.wait(); + Pipe::write(q,HostPipeWriteData); assert(PipeWriteVal == 9); } From 15136a6379ed1adc0d7bb13e65b1eda882271c0c Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 09:02:22 -0700 Subject: [PATCH 48/56] run clang format --- sycl/unittests/pipes/host_pipe_registration.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index afd7506b982ac..d46f5aea1eaa4 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -95,7 +95,8 @@ pi_result after_piDeviceGetInfo(pi_device device, pi_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) { constexpr char MockSupportedExtensions[] = - "cl_khr_fp64 cl_khr_fp16 cl_khr_il_program cl_intel_program_scope_host_pipe"; + "cl_khr_fp64 cl_khr_fp16 cl_khr_il_program " + "cl_intel_program_scope_host_pipe"; switch (param_name) { case PI_DEVICE_INFO_EXTENSIONS: { if (param_value) { @@ -141,19 +142,20 @@ class PipeTest : public ::testing::Test { TEST_F(PipeTest, Basic) { // Fake extension - Mock.redefineAfter(after_piDeviceGetInfo); + Mock.redefineAfter( + after_piDeviceGetInfo); // Device registration static sycl::unittest::PiImage Img = generateDefaultImage(); static sycl::unittest::PiImageArray<1> ImgArray{&Img}; - //Testing read + // Testing read int HostPipeReadData; HostPipeReadData = Pipe::read(q); assert(HostPipeReadData == PipeReadVal); // Testing write int HostPipeWriteData = 9; - Pipe::write(q,HostPipeWriteData); + Pipe::write(q, HostPipeWriteData); assert(PipeWriteVal == 9); } From 69136609d00d1499e57c005908f68360877fcab0 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 09:30:00 -0700 Subject: [PATCH 49/56] Empty commit From 39ab2b9fa8512be91fd7377ba6c0d9b3c103288d Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 10:02:05 -0700 Subject: [PATCH 50/56] fixup --- sycl/include/sycl/ext/intel/experimental/pipes.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index debce8e1a57fd..2313cf94e06ca 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -104,7 +104,7 @@ class pipe : public pipe_base { const void *HostPipePtr = &m_Storage; const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); - const void *DataPtr = &Data; + void *DataPtr = &Data; event E = Q.submit([=](handler &CGH) { CGH.ext_intel_write_host_pipe( @@ -249,7 +249,7 @@ class pipe : public pipe_base { } const void *HostPipePtr = &m_Storage; const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); - const void *DataPtr = &Data; + void *DataPtr = &Data; event E = Q.submit([=](handler &CGH) { CGH.ext_intel_write_host_pipe(PipeName, (void *)DataPtr, sizeof(_dataT), true /*blocking */); From 05a7dff4d9c275e2fa65be1d1f788673566281a2 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 10:49:38 -0700 Subject: [PATCH 51/56] fixup const qualifier --- sycl/include/sycl/ext/intel/experimental/pipes.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 2313cf94e06ca..f2e687d60570f 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -104,11 +104,11 @@ class pipe : public pipe_base { const void *HostPipePtr = &m_Storage; const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); - void *DataPtr = &Data; + void *DataPtr = const_cast(&Data); event E = Q.submit([=](handler &CGH) { CGH.ext_intel_write_host_pipe( - PipeName, (void *)DataPtr, sizeof(_dataT) /* non-blocking */); + PipeName, DataPtr, sizeof(_dataT) /* non-blocking */); }); E.wait(); Success = E.get_info() == @@ -249,7 +249,7 @@ class pipe : public pipe_base { } const void *HostPipePtr = &m_Storage; const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); - void *DataPtr = &Data; + void *DataPtr = const_cast(&Data); event E = Q.submit([=](handler &CGH) { CGH.ext_intel_write_host_pipe(PipeName, (void *)DataPtr, sizeof(_dataT), true /*blocking */); From bcec63529d39a2caf0432d2d3a5aa5f2caebb53f Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 11:00:34 -0700 Subject: [PATCH 52/56] remove unnecessary cast --- sycl/include/sycl/ext/intel/experimental/pipes.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index f2e687d60570f..7cf3c4509f681 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -251,7 +251,7 @@ class pipe : public pipe_base { const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); void *DataPtr = const_cast(&Data); event E = Q.submit([=](handler &CGH) { - CGH.ext_intel_write_host_pipe(PipeName, (void *)DataPtr, + CGH.ext_intel_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), true /*blocking */); }); E.wait(); From 979201aa23b0201ca1dff3b325bc9c4f499f73bd Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 11:23:46 -0700 Subject: [PATCH 53/56] fixup the const cast --- sycl/include/sycl/ext/intel/experimental/pipes.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/pipes.hpp b/sycl/include/sycl/ext/intel/experimental/pipes.hpp index 7cf3c4509f681..7dedc1d4cbc26 100644 --- a/sycl/include/sycl/ext/intel/experimental/pipes.hpp +++ b/sycl/include/sycl/ext/intel/experimental/pipes.hpp @@ -104,7 +104,7 @@ class pipe : public pipe_base { const void *HostPipePtr = &m_Storage; const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); - void *DataPtr = const_cast(&Data); + void *DataPtr = const_cast<_dataT *>(&Data); event E = Q.submit([=](handler &CGH) { CGH.ext_intel_write_host_pipe( @@ -249,7 +249,7 @@ class pipe : public pipe_base { } const void *HostPipePtr = &m_Storage; const std::string PipeName = pipe_base::get_pipe_name(HostPipePtr); - void *DataPtr = const_cast(&Data); + void *DataPtr = const_cast<_dataT *>(&Data); event E = Q.submit([=](handler &CGH) { CGH.ext_intel_write_host_pipe(PipeName, DataPtr, sizeof(_dataT), true /*blocking */); From 839d7eee193d306f35875d3c0306a297dda3a6d9 Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 11:46:20 -0700 Subject: [PATCH 54/56] fix the default switch in the unittest --- sycl/unittests/pipes/host_pipe_registration.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index d46f5aea1eaa4..dd18d98d864d1 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -108,6 +108,7 @@ pi_result after_piDeviceGetInfo(pi_device device, pi_device_info param_name, *param_value_size_ret = sizeof(MockSupportedExtensions); return PI_SUCCESS; } + default:; } return PI_SUCCESS; } From 0b2ebd24ea44ff8899cd84a9da0e78c88973f1ed Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 16:12:36 -0700 Subject: [PATCH 55/56] Empty commit to try triggering CI From 302aa8601c4874b1312fba423c209b171621bb8a Mon Sep 17 00:00:00 2001 From: Zibai Wang Date: Wed, 29 Mar 2023 16:59:49 -0700 Subject: [PATCH 56/56] Empty commit to try triggering CI