Skip to content

Commit fd438ca

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (#1)
2 parents daad034 + 850fb9f commit fd438ca

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

sycl/include/CL/sycl/detail/queue_impl.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,15 @@ class queue_impl {
352352
handler Handler(std::move(Self), MHostQueue);
353353
CGF(Handler);
354354
event Event = Handler.finalize();
355-
{
356-
std::lock_guard<mutex_class> Guard(MMutex);
357-
MEvents.push_back(Event);
358-
}
355+
addEvent(Event);
359356
return Event;
360357
}
361358

359+
/// Stores an event that should be associated with the queue
360+
///
361+
/// @param Event is the event to be stored
362+
void addEvent(event Event);
363+
362364
/// Protects all the fields that can be changed by class' methods.
363365
mutex_class MMutex;
364366

sycl/source/detail/queue_impl.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ event queue_impl::memset(shared_ptr_class<detail::queue_impl> Impl, void *Ptr,
4545
if (Context.is_host())
4646
return event();
4747

48-
return event(pi::cast<cl_event>(Event), Context);
48+
event ResEvent{pi::cast<cl_event>(Event), Context};
49+
addEvent(ResEvent);
50+
return ResEvent;
4951
}
5052

5153
event queue_impl::memcpy(shared_ptr_class<detail::queue_impl> Impl, void *Dest,
@@ -57,7 +59,9 @@ event queue_impl::memcpy(shared_ptr_class<detail::queue_impl> Impl, void *Dest,
5759
if (Context.is_host())
5860
return event();
5961

60-
return event(pi::cast<cl_event>(Event), Context);
62+
event ResEvent{pi::cast<cl_event>(Event), Context};
63+
addEvent(ResEvent);
64+
return ResEvent;
6165
}
6266

6367
event queue_impl::mem_advise(const void *Ptr, size_t Length, int Advice) {
@@ -72,8 +76,16 @@ event queue_impl::mem_advise(const void *Ptr, size_t Length, int Advice) {
7276
Plugin.call<PiApiKind::piextUSMEnqueueMemAdvise>(getHandleRef(), Ptr, Length,
7377
Advice, &Event);
7478

75-
return event(pi::cast<cl_event>(Event), Context);
79+
event ResEvent{pi::cast<cl_event>(Event), Context};
80+
addEvent(ResEvent);
81+
return ResEvent;
7682
}
83+
84+
void queue_impl::addEvent(event Event) {
85+
std::lock_guard<mutex_class> Guard(MMutex);
86+
MEvents.push_back(std::move(Event));
87+
}
88+
7789
} // namespace detail
7890
} // namespace sycl
7991
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/test/usm/queue_wait.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %clangxx -fsycl %s -o %t.out
2+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
6+
#include <CL/sycl.hpp>
7+
8+
#include <cassert>
9+
#include <cstddef>
10+
11+
using namespace cl::sycl;
12+
13+
// This test checks that queue USM functions are properly waited for during
14+
// calls to queue::wait().
15+
16+
int main() {
17+
const std::size_t Size = 32;
18+
queue Q;
19+
std::cout << Q.is_host() << std::endl;
20+
device Dev = Q.get_device();
21+
context Ctx = Q.get_context();
22+
if (!(Dev.get_info<info::device::usm_device_allocations>() &&
23+
Dev.get_info<info::device::usm_host_allocations>()))
24+
return 0;
25+
26+
unsigned char *DevArr = (unsigned char *)malloc_device(Size, Dev, Ctx);
27+
assert(DevArr);
28+
unsigned char *HostArr = (unsigned char *)malloc_host(Size, Ctx);
29+
assert(HostArr);
30+
31+
Q.memset(DevArr, 42, Size);
32+
Q.wait();
33+
Q.memcpy(HostArr, DevArr, Size);
34+
Q.wait();
35+
36+
for (std::size_t i = 0; i < Size; ++i)
37+
assert(HostArr[i] == 42);
38+
39+
free(DevArr, Ctx);
40+
free(HostArr, Ctx);
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)