Skip to content

Commit f37a1cf

Browse files
vladimirlazromanovvlad
authored andcommitted
[SYCL] Fix getting host objects for impl objects (#967)
Impl fields in context_impl and program_impl are initialized with nullptr for host opbjects. That caused segfault on accessing them. Create host objects on access time. Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 1439e0a commit f37a1cf

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

sycl/include/CL/sycl/detail/program_impl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ class program_impl {
324324
}
325325

326326
context get_context() const {
327+
if (is_host())
328+
return context();
327329
return createSyclObjFromImpl<context>(Context);
328330
}
329331

sycl/source/detail/context_impl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ cl_uint context_impl::get_info<info::context::reference_count>() const {
101101
this->getHandleRef());
102102
}
103103
template <> platform context_impl::get_info<info::context::platform>() const {
104+
if (is_host())
105+
return platform();
104106
return createSyclObjFromImpl<platform>(MPlatform);
105107
}
106108
template <>

sycl/test/basic_tests/info.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ int main() {
310310
dev, "Preferred interop user sync");
311311
// TODO test once subdevice creation is enabled
312312
// print_info<info::device::parent_device, device>(dev, "Parent device");
313-
if(!dev.is_host()){
313+
if (!dev.is_host()) {
314314
try {
315315
print_info<info::device::parent_device, device>(dev, "Parent device");
316316
} catch (invalid_object_error e) {
@@ -343,4 +343,21 @@ int main() {
343343
print_info<info::platform::vendor, string_class>(plt, "Vendor");
344344
print_info<info::platform::extensions, vector_class<string_class>>(
345345
plt, "Extensions");
346+
347+
std::cout << separator << "Queue information\n" << separator;
348+
queue q(selector);
349+
auto qdev = q.get_info<cl::sycl::info::queue::device>();
350+
std::cout << "Device from queue information\n";
351+
print_info<info::device::name, string_class>(qdev, "Name");
352+
auto ctx = q.get_info<cl::sycl::info::queue::context>();
353+
354+
std::cout << separator << "Context information\n" << separator;
355+
std::cout << "Devices from context information\n";
356+
auto cdevs = ctx.get_info<cl::sycl::info::context::devices>();
357+
for (auto cdev : cdevs) {
358+
print_info<info::device::name, string_class>(cdev, "Name");
359+
}
360+
std::cout << separator << "Platform from context information\n" << separator;
361+
auto cplt = ctx.get_info<cl::sycl::info::context::platform>();
362+
print_info<info::platform::name, string_class>(cplt, "Name");
346363
}

0 commit comments

Comments
 (0)