Skip to content

Commit 6a0e279

Browse files
s-kanaevromanovvlad
authored andcommitted
[SYCL] Fixed crash when a non-nullptr_t 0x0 value is passed to the set_final_data method (#1004)
Signed-off-by: Sergey Kanaev <[email protected]>
1 parent 0867a38 commit 6a0e279

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,14 @@ template <typename AllocatorT> class SYCLMemObjT : public SYCLMemObjI {
165165

166166
template <typename Destination>
167167
EnableIfOutputPointerT<Destination> set_final_data(Destination FinalData) {
168-
MUploadDataFunctor = [this, FinalData]() {
169-
EventImplPtr Event = updateHostMemory(FinalData);
170-
if (Event)
171-
Event->wait(Event);
172-
};
168+
if (!FinalData)
169+
MUploadDataFunctor = nullptr;
170+
else
171+
MUploadDataFunctor = [this, FinalData]() {
172+
EventImplPtr Event = updateHostMemory(FinalData);
173+
if (Event)
174+
Event->wait(Event);
175+
};
173176
}
174177

175178
template <typename Destination>

sycl/test/basic_tests/image.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ int main() {
7373
});
7474
}
7575

76+
// image with write accessor to it in kernel
77+
{
78+
int NX = 32;
79+
int NY = 32;
80+
81+
sycl::image<2> Img(sycl::image_channel_order::rgba,
82+
sycl::image_channel_type::fp32,
83+
sycl::range<2>(NX, NY));
84+
85+
sycl::queue Q;
86+
Q.submit([&](sycl::handler &CGH) {
87+
auto ImgAcc = Img.get_access<sycl::float4, sycl::access::mode::write>(
88+
CGH);
89+
90+
sycl::nd_range<2> Rng(sycl::range<2>(NX, NY), sycl::range<2>(16, 16));
91+
92+
CGH.parallel_for<class sample>(Rng, [=](sycl::nd_item<2> Item) {
93+
sycl::id<2> Idx = Item.get_global_id();
94+
sycl::float4 C(0.5f, 0.5f, 0.2f, 1.0f);
95+
ImgAcc.write(sycl::int2(Idx[0], Idx[1]), C);
96+
});
97+
98+
}).wait_and_throw();
99+
}
100+
76101
std::cout << "Success" << std::endl;
77102
return 0;
78103
}

0 commit comments

Comments
 (0)