[llvm] [libsycl] Initial prefetch implementation for queue (PR #212104)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 07:22:37 PDT 2026


================
@@ -0,0 +1,56 @@
+#include <mock/helpers.hpp>
+
+#include <sycl/__impl/queue.hpp>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using namespace sycl;
+using namespace ::testing;
+
+TEST(Queue, TwoPrefetches) {
+  constexpr std::size_t NumBytes = 1024;
+  constexpr int NPrefetches = 2;
+
+  mock::MockWrapper Mock;
+  queue Q;
+
+  void *Ptr = reinterpret_cast<void *>(1);
+
+  bool IsCpu = Q.get_device().is_cpu();
+  ol_mem_migration_flags_t ExpectedFlag =
+      IsCpu ? OL_MEM_MIGRATION_FLAG_DEVICE_TO_HOST
+            : OL_MEM_MIGRATION_FLAG_HOST_TO_DEVICE;
+
+  EXPECT_CALL(Mock.get(), olMemPrefetch(_, 1, _, _, ExpectedFlag))
+      .Times(NPrefetches)
+      .WillRepeatedly([&](ol_queue_handle_t Queue, size_t Count,
+                          const void **Mems, const size_t *Sizes,
+                          ol_mem_migration_flags_t Flags) -> ol_result_t {
+        EXPECT_NE(Queue, nullptr);
+        EXPECT_EQ(Count, 1u);
+        EXPECT_EQ(Mems[0], Ptr);
+        EXPECT_EQ(Sizes[0], NumBytes);
+        EXPECT_EQ(Flags, ExpectedFlag);
+        return OL_SUCCESS;
+      });
+
+  EXPECT_CALL(Mock.get(), olCreateEvent(_, _, _)).Times(NPrefetches);
+
+  event Event = Q.prefetch(Ptr, NumBytes);
+
+  // second prefetch depeends on the first one
----------------
Robertkq wrote:

fixed

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


More information about the llvm-commits mailing list