Skip to content

Commit 155fe36

Browse files
authored
[SYCL] Fix assertion at host pipe initialization in case of multiple TUs (#16756)
If there are multiple translation units using the host pipe then initialize function will be called multiple times with the same pointer because special function for pipe registration and initialization (__sycl_host_pipe_registration) has to be emitted by frontend for each translation unit. Just assert that pointer is the same.
1 parent 8a27954 commit 155fe36

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

sycl/source/detail/host_pipe_map_entry.hpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ struct HostPipeMapEntry {
4343
}
4444

4545
void initialize(const void *HostPipePtr) {
46-
assert(!MHostPipePtr && "Host pipe pointer has already been initialized.");
46+
// If there are multiple translation units using the host pipe then
47+
// initialize function will be called multiple times with the same pointer
48+
// because special function for pipe registration and initialization has to
49+
// be emitted by frontend for each translation unit. Just make sure that
50+
// pointer is the same.
51+
if (MHostPipePtr) {
52+
assert(MHostPipePtr == HostPipePtr &&
53+
"Host pipe intializations disagree on address of the host pipe on "
54+
"host.");
55+
return;
56+
}
57+
4758
MHostPipePtr = HostPipePtr;
4859
}
4960

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "mypipe.hpp"
2+
#include <cstdint>
3+
4+
void KernelFunctor::operator()() const {
5+
uint32_t data = 2;
6+
my_pipe::write(data);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <cstdint>
2+
#include <sycl/detail/core.hpp>
3+
#include <sycl/ext/intel/fpga_extensions.hpp>
4+
5+
#pragma once
6+
7+
struct KernelFunctor {
8+
using my_pipe =
9+
sycl::ext::intel::experimental::pipe<struct sample_host_pipe, uint32_t>;
10+
SYCL_EXTERNAL void operator()() const;
11+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// REQUIRES: accelerator
2+
// RUN: %clangxx -fsycl -fintelfpga %s %S/Inputs/kernel.cpp -I%S/Inputs -o %t.out
3+
// RUN: %{run} %t.out | FileCheck %s
4+
5+
// Test checks that host pipe initialization doesn't fail if pipe is used in
6+
// multiple translation units.
7+
8+
#include "mypipe.hpp"
9+
#include <iostream>
10+
11+
int main() {
12+
sycl::queue q{sycl::ext::intel::fpga_emulator_selector_v};
13+
q.submit([&](sycl::handler &cgh) { cgh.single_task(KernelFunctor{}); });
14+
uint32_t result = KernelFunctor::my_pipe::read(q);
15+
q.wait();
16+
// CHECK: 2
17+
std::cout << result << std::endl;
18+
19+
return 0;
20+
}

0 commit comments

Comments
 (0)