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

Alexey Bader via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 21 09:02:17 PST 2026


================
@@ -11,18 +11,57 @@
 #include <detail/offload/offload_utils.hpp>
 
 #include <array>
-#include <unordered_map>
 
 _LIBSYCL_BEGIN_NAMESPACE_SYCL
 
 namespace detail {
 
+// Platforms for this backend
+range_view<const ol_platform_handle_t> OffloadTopology::getPlatforms() const {
+  return {MPlatforms.data(), MPlatforms.size()};
+}
+
+// Devices for a specific platform (platform_id is index into Platforms)
+range_view<ol_device_handle_t>
+OffloadTopology::getDevices(size_t PlatformId) const {
+  if (PlatformId >= MDeviceRange.size()) {
+    assert(false && "Platform index exceeds number of platforms.");
+    return {nullptr, 0};
+  }
----------------
bader wrote:

> In general we don't expect this function to receive out of range PlatformID so this assert must be always unreachable. Keeping it here for debug purposes.

If so, `assert(PlatformId < MDeviceRange.size() && "Platform index exceeds number of platforms.");` should be enough.

Alternative option is to return an empty range for out-of-range indices but remove an assertion.

Using both is very confusing.

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


More information about the llvm-commits mailing list