Skip to content

Commit e4d513c

Browse files
committed
Add pi extension API for host pipes
Setup lower runtime extension functions for host pipes. See also #5766 #5851 Host pipe sycl spec: #5838
1 parent 031f829 commit e4d513c

File tree

11 files changed

+302
-12
lines changed

11 files changed

+302
-12
lines changed

buildbot/dependency.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ def do_dependency(args):
4949
# fetch OpenCL headers
5050
ocl_header_dir = os.path.join(args.obj_dir, "OpenCL-Headers")
5151
if not os.path.isdir(ocl_header_dir):
52-
clone_cmd = ["git", "clone", "https://github.com/KhronosGroup/OpenCL-Headers",
53-
"OpenCL-Headers", "-b", "main"]
52+
clone_cmd = ["git", "clone", "https://github.com/sherry-yuan/OpenCL-Headers",
53+
"OpenCL-Headers", "-b", "host_pipe"] # TODO: Remove change once upstream header changed
5454
subprocess.check_call(clone_cmd, cwd=args.obj_dir)
5555
else:
5656
fetch_cmd = ["git", "pull", "--ff", "--ff-only", "origin"]
5757
subprocess.check_call(fetch_cmd, cwd=ocl_header_dir)
5858

5959
# Checkout fixed version to avoid unexpected issues coming from upstream
6060
# Specific version can be uplifted as soon as such need arise
61-
checkout_cmd = ["git", "checkout", "23710f1b99186065c1768fc3098ba681adc0f253"]
61+
checkout_cmd = ["git", "checkout", "1f2cb76195fb77be7c0b4d811ecff244c864d2e2"] # TODO: Remove change once upstream header changed
6262
subprocess.check_call(checkout_cmd, cwd=ocl_header_dir)
6363

6464
# fetch and build OpenCL ICD loader

opencl/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ endif()
1414
# Repo URLs
1515

1616
set(OCL_HEADERS_REPO
17-
"https://github.com/KhronosGroup/OpenCL-Headers.git")
17+
"https://github.com/sherry-yuan/OpenCL-Headers.git")
1818
set(OCL_LOADER_REPO
1919
"https://github.com/KhronosGroup/OpenCL-ICD-Loader.git")
2020

2121
# Repo tags/hashes
2222

23-
set(OCL_HEADERS_TAG dcd5bede6859d26833cd85f0d6bbcee7382dc9b3)
24-
set(OCL_LOADER_TAG 5d9177ee79bfbcc75ee9a8cff6415eab2c3113f6)
23+
set(OCL_HEADERS_TAG 1f2cb76195fb77be7c0b4d811ecff244c864d2e2)
24+
set(OCL_LOADER_TAG 5f8249691ec8c25775789498951f8e9eb62c201d)
2525

2626
# OpenCL Headers
2727
if(NOT OpenCL_HEADERS)

sycl/include/CL/sycl/detail/pi.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ _PI_API(piextUSMEnqueueMemcpy)
130130
_PI_API(piextUSMEnqueuePrefetch)
131131
_PI_API(piextUSMEnqueueMemAdvise)
132132
_PI_API(piextUSMGetMemAllocInfo)
133+
// Host pipes
134+
_PI_API(piextEnqueueReadHostPipe)
135+
_PI_API(piextEnqueueWriteHostPipe)
133136

134137
_PI_API(piextKernelSetArgMemObj)
135138
_PI_API(piextKernelSetArgSampler)

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,56 @@ __SYCL_EXPORT pi_result piextUSMGetMemAllocInfo(
17841784
pi_context context, const void *ptr, pi_mem_alloc_info param_name,
17851785
size_t param_value_size, void *param_value, size_t *param_value_size_ret);
17861786

1787+
///
1788+
// Host Pipes
1789+
///
1790+
1791+
/// Read from pipe of a given name
1792+
///
1793+
/// @param queue a valid host command-queue in which the read / write command
1794+
/// will be queued. command_queue and program must be created with the same
1795+
/// OpenCL context.
1796+
/// @param program a program object with a successfully built executable.
1797+
/// @param pipe_symbol the name of the program scope pipe global variable.
1798+
/// @param blocking indicate if the read and write operations are blocking or
1799+
/// non-blocking
1800+
/// @param ptr a pointer to buffer in host memory that will hold resulting data
1801+
/// from pipe
1802+
/// @param size size of the memory region to read or write, in bytes.
1803+
/// @param num_events_in_waitlist number of events in the wait list.
1804+
/// @param events_waitlist specify events that need to complete before this
1805+
/// particular command can be executed.
1806+
/// @param event returns an event object that identifies this read / write
1807+
/// command and can be used to query or queue a wait for this command to
1808+
/// complete.
1809+
__SYCL_EXPORT pi_result piextEnqueueReadHostPipe(
1810+
pi_queue queue, pi_program program, const char *pipe_symbol,
1811+
pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist,
1812+
const pi_event *events_waitlist, pi_event *event);
1813+
1814+
/// Write to pipe of a given name
1815+
///
1816+
/// @param queue a valid host command-queue in which the read / write command
1817+
/// will be queued. command_queue and program must be created with the same
1818+
/// OpenCL context.
1819+
/// @param program a program object with a successfully built executable.
1820+
/// @param pipe_symbol the name of the program scope pipe global variable.
1821+
/// @param blocking indicate if the read and write operations are blocking or
1822+
/// non-blocking
1823+
/// @param ptr a pointer to buffer in host memory that holds data to be written
1824+
/// to host pipe.
1825+
/// @param size size of the memory region to read or write, in bytes.
1826+
/// @param num_events_in_waitlist number of events in the wait list.
1827+
/// @param events_waitlist specify events that need to complete before this
1828+
/// particular command can be executed.
1829+
/// @param event returns an event object that identifies this read / write
1830+
/// command and can be used to query or queue a wait for this command to
1831+
/// complete.
1832+
__SYCL_EXPORT pi_result piextEnqueueWriteHostPipe(
1833+
pi_queue queue, pi_program program, const char *pipe_symbol,
1834+
pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist,
1835+
const pi_event *events_waitlist, pi_event *event);
1836+
17871837
/// API to get Plugin internal data, opaque to SYCL RT. Some devices whose
17881838
/// device code is compiled by the host compiler (e.g. CPU emulators) may use it
17891839
/// to access some device code functionality implemented in/behind the plugin.

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4949,6 +4949,43 @@ pi_result cuda_piextUSMGetMemAllocInfo(pi_context context, const void *ptr,
49494949
return result;
49504950
}
49514951

4952+
/// Host Pipes
4953+
pi_result cuda_piextEnqueueReadHostPipe(
4954+
pi_queue queue, pi_program program, const char *pipe_symbol,
4955+
pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist,
4956+
const pi_event *events_waitlist, pi_event *event) {
4957+
(void)queue;
4958+
(void)program;
4959+
(void)pipe_symbol;
4960+
(void)blocking;
4961+
(void)ptr;
4962+
(void)size;
4963+
(void)num_events_in_waitlist;
4964+
(void)events_waitlist;
4965+
(void)event;
4966+
4967+
cl::sycl::detail::pi::die("cuda_piextEnqueueReadHostPipe not implemented");
4968+
return {};
4969+
}
4970+
4971+
pi_result cuda_piextEnqueueWriteHostPipe(
4972+
pi_queue queue, pi_program program, const char *pipe_symbol,
4973+
pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist,
4974+
const pi_event *events_waitlist, pi_event *event) {
4975+
(void)queue;
4976+
(void)program;
4977+
(void)pipe_symbol;
4978+
(void)blocking;
4979+
(void)ptr;
4980+
(void)size;
4981+
(void)num_events_in_waitlist;
4982+
(void)events_waitlist;
4983+
(void)event;
4984+
4985+
cl::sycl::detail::pi::die("cuda_piextEnqueueWriteHostPipe not implemented");
4986+
return {};
4987+
}
4988+
49524989
// This API is called by Sycl RT to notify the end of the plugin lifetime.
49534990
// TODO: add a global variable lifetime management code here (see
49544991
// pi_level_zero.cpp for reference) Currently this is just a NOOP.
@@ -5091,6 +5128,10 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
50915128
_PI_CL(piextUSMEnqueueMemAdvise, cuda_piextUSMEnqueueMemAdvise)
50925129
_PI_CL(piextUSMGetMemAllocInfo, cuda_piextUSMGetMemAllocInfo)
50935130

5131+
// Host Pipe
5132+
_PI_CL(piextEnqueueReadHostPipe, cuda_piextEnqueueReadHostPipe)
5133+
_PI_CL(piextEnqueueWriteHostPipe, cuda_piextEnqueueWriteHostPipe)
5134+
50945135
_PI_CL(piextKernelSetArgMemObj, cuda_piextKernelSetArgMemObj)
50955136
_PI_CL(piextKernelSetArgSampler, cuda_piextKernelSetArgSampler)
50965137
_PI_CL(piTearDown, cuda_piTearDown)

sycl/plugins/esimd_emulator/pi_esimd_emulator.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,25 @@ pi_result piextUSMGetMemAllocInfo(pi_context, const void *, pi_mem_alloc_info,
18871887
DIE_NO_IMPLEMENTATION;
18881888
}
18891889

1890+
/// Host Pipes
1891+
pi_result piextEnqueueReadHostPipe(pi_queue queue, pi_program program,
1892+
const char *pipe_symbol, pi_bool blocking,
1893+
void *ptr, size_t size,
1894+
pi_uint32 num_events_in_waitlist,
1895+
const pi_event *events_waitlist,
1896+
pi_event *event) {
1897+
DIE_NO_IMPLEMENTATION;
1898+
}
1899+
1900+
pi_result piextEnqueueWriteHostPipe(pi_queue queue, pi_program program,
1901+
const char *pipe_symbol, pi_bool blocking,
1902+
void *ptr, size_t size,
1903+
pi_uint32 num_events_in_waitlist,
1904+
const pi_event *events_waitlist,
1905+
pi_event *event) {
1906+
DIE_NO_IMPLEMENTATION;
1907+
}
1908+
18901909
pi_result piKernelSetExecInfo(pi_kernel, pi_kernel_exec_info, size_t,
18911910
const void *) {
18921911
DIE_NO_IMPLEMENTATION;

sycl/plugins/hip/pi_hip.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,6 +4840,45 @@ pi_result hip_piextUSMGetMemAllocInfo(pi_context context, const void *ptr,
48404840
return result;
48414841
}
48424842

4843+
/// Host Pipes
4844+
pi_result hip_piextEnqueueReadHostPipe(pi_queue queue, pi_program program,
4845+
const char *pipe_symbol,
4846+
pi_bool blocking, void *ptr, size_t size,
4847+
pi_uint32 num_events_in_waitlist,
4848+
const pi_event *events_waitlist,
4849+
pi_event *event) {
4850+
(void)queue;
4851+
(void)program;
4852+
(void)pipe_symbol;
4853+
(void)blocking;
4854+
(void)ptr;
4855+
(void)size;
4856+
(void)num_events_in_waitlist;
4857+
(void)events_waitlist;
4858+
(void)event;
4859+
4860+
cl::sycl::detail::pi::die("hip_piextEnqueueReadHostPipe not implemented");
4861+
return {};
4862+
}
4863+
4864+
pi_result hip_piextEnqueueWriteHostPipe(
4865+
pi_queue queue, pi_program program, const char *pipe_symbol,
4866+
pi_bool blocking, void *ptr, size_t size, pi_uint32 num_events_in_waitlist,
4867+
const pi_event *events_waitlist, pi_event *event) {
4868+
(void)queue;
4869+
(void)program;
4870+
(void)pipe_symbol;
4871+
(void)blocking;
4872+
(void)ptr;
4873+
(void)size;
4874+
(void)num_events_in_waitlist;
4875+
(void)events_waitlist;
4876+
(void)event;
4877+
4878+
cl::sycl::detail::pi::die("hip_piextEnqueueWriteHostPipe not implemented");
4879+
return {};
4880+
}
4881+
48434882
// This API is called by Sycl RT to notify the end of the plugin lifetime.
48444883
// TODO: add a global variable lifetime management code here (see
48454884
// pi_level_zero.cpp for reference) Currently this is just a NOOP.
@@ -4981,6 +5020,10 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
49815020
_PI_CL(piextUSMEnqueueMemAdvise, hip_piextUSMEnqueueMemAdvise)
49825021
_PI_CL(piextUSMGetMemAllocInfo, hip_piextUSMGetMemAllocInfo)
49835022

5023+
// Host Pipe
5024+
_PI_CL(piextEnqueueReadHostPipe, hip_piextEnqueueReadHostPipe)
5025+
_PI_CL(piextEnqueueWriteHostPipe, hip_piextEnqueueWriteHostPipe)
5026+
49845027
_PI_CL(piextKernelSetArgMemObj, hip_piextKernelSetArgMemObj)
49855028
_PI_CL(piextKernelSetArgSampler, hip_piextKernelSetArgSampler)
49865029
_PI_CL(piTearDown, hip_piTearDown)

sycl/plugins/level_zero/pi_level_zero.cpp

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

7891+
/// API for Read from host pipe.
7892+
///
7893+
/// \param Queue is the queue
7894+
/// \param Program is the program containing the device variable
7895+
/// \param PipeSymbol is the unique identifier for the device variable
7896+
/// \param Blocking is true if the write should block
7897+
/// \param Ptr is a pointer to where the data will be copied to
7898+
/// \param Size is size of the data that is read/written from/to pipe
7899+
/// \param NumEventsInWaitList is a number of events in the wait list
7900+
/// \param EventWaitList is the wait list
7901+
/// \param Event is the resulting event
7902+
pi_result piextEnqueueReadHostPipe(pi_queue Queue, pi_program Program,
7903+
const char *PipeSymbol, pi_bool Blocking,
7904+
void *Ptr, size_t Size,
7905+
pi_uint32 NumEventsInWaitList,
7906+
const pi_event *EventsWaitList,
7907+
pi_event *Event) {
7908+
(void)Queue;
7909+
(void)Program;
7910+
(void)PipeSymbol;
7911+
(void)Blocking;
7912+
(void)Ptr;
7913+
(void)Size;
7914+
(void)NumEventsInWaitList;
7915+
(void)EventsWaitList;
7916+
(void)Event;
7917+
7918+
PI_ASSERT(Queue, PI_INVALID_QUEUE);
7919+
7920+
die("piextEnqueueReadHostPipe: not implemented");
7921+
return {};
7922+
}
7923+
7924+
/// API for write to pipe of a given name.
7925+
///
7926+
/// \param Queue is the queue
7927+
/// \param Program is the program containing the device variable
7928+
/// \param PipeSymbol is the unique identifier for the device variable
7929+
/// \param Blocking is true if the write should block
7930+
/// \param Ptr is a pointer to where the data must be copied from
7931+
/// \param Size is size of the data that is read/written from/to pipe
7932+
/// \param NumEventsInWaitList is a number of events in the wait list
7933+
/// \param EventWaitList is the wait list
7934+
/// \param Event is the resulting event
7935+
pi_result piextEnqueueWriteHostPipe(pi_queue Queue, pi_program Program,
7936+
const char *PipeSymbol, pi_bool Blocking,
7937+
void *Ptr, size_t Size,
7938+
pi_uint32 NumEventsInWaitList,
7939+
const pi_event *EventsWaitList,
7940+
pi_event *Event) {
7941+
(void)Queue;
7942+
(void)Program;
7943+
(void)PipeSymbol;
7944+
(void)Blocking;
7945+
(void)Ptr;
7946+
(void)Size;
7947+
(void)NumEventsInWaitList;
7948+
(void)EventsWaitList;
7949+
(void)Event;
7950+
7951+
PI_ASSERT(Queue, PI_INVALID_QUEUE);
7952+
7953+
die("piextEnqueueWriteHostPipe: not implemented");
7954+
return {};
7955+
}
7956+
78917957
pi_result piKernelSetExecInfo(pi_kernel Kernel, pi_kernel_exec_info ParamName,
78927958
size_t ParamValueSize, const void *ParamValue) {
78937959
(void)ParamValueSize;

0 commit comments

Comments
 (0)