[llvm] [SYCL] Add sycl::device initial implementation (PR #176972)

Dmitry Rogozhkin via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 20 10:58:12 PST 2026


================
@@ -53,6 +59,62 @@ PlatformImpl::PlatformImpl(ol_platform_handle_t Platform, size_t PlatformIndex,
                sizeof(Backend), &Backend);
   MBackend = convertBackend(Backend);
   MOffloadBackend = Backend;
+
+  const auto &Topologies = getOffloadTopologies();
+  auto RootTopologyIt = std::find_if(
+      Topologies.begin(), Topologies.end(), [&](const OffloadTopology &Topo) {
+        return Topo.getBackend() == MOffloadBackend;
+      });
+
+  assert(RootTopologyIt != Topologies.end() &&
+         "Root topology for platform must always exist");
+  auto DevRange = RootTopologyIt->getDevices(MOffloadPlatformIndex);
+  MRootDevices.reserve(DevRange.size());
+  std::for_each(DevRange.begin(), DevRange.end(),
+                [&](const ol_device_handle_t &Device) {
+                  MRootDevices.emplace_back(std::make_unique<DeviceImpl>(
+                      Device, *this, DeviceImpl::PrivateTag{}));
+                });
+}
+
+const std::vector<DeviceImplUPtr> &PlatformImpl::getRootDevices() const {
+  return MRootDevices;
+}
+
+bool PlatformImpl::has(aspect Aspect) const {
+  const auto &Devices = getRootDevices();
+  return std::all_of(
+      Devices.begin(), Devices.end(),
+      [&Aspect](const DeviceImplUPtr &Device) { return Device->has(Aspect); });
 }
+
+void PlatformImpl::iterateDevices(
+    info::device_type DeviceType,
+    std::function<void(DeviceImpl *)> callback) const {
+  // Early exit if host device is requested
+  if (DeviceType == info::device_type::host)
+    return;
+  if (DeviceType == info::device_type::custom)
+    return;
+  if (DeviceType == info::device_type::accelerator)
+    return;
+
+  const auto &DeviceImpls = getRootDevices();
+
+  // TODO: need an way to get default device from liboffload
+  // as temporal solution just return the first device for DeviceType ==
+  // automatic
----------------
dvrogozh wrote:

```suggestion
  // TODO: Need a way to get default device from liboffload.
  // As a temporal solution just return the first device for DeviceType ==
  // automatic.
```

https://github.com/llvm/llvm-project/pull/176972


More information about the llvm-commits mailing list