[llvm] [libsycl] Implement memcpy API (PR #205369)

Kseniya Tikhomirova via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 24 06:25:35 PDT 2026


================
@@ -0,0 +1,116 @@
+// REQUIRES: any-device
+// RUN: %clangxx %sycl_options %s -o %t.out
+// RUN: %t.out
+
+#include <sycl/sycl.hpp>
+
+#include <cstddef>
+#include <numeric>
+#include <tuple>
+
+using namespace sycl;
+
+constexpr std::size_t DataSize = 1024;
+constexpr std::size_t NumBytes = DataSize * sizeof(int);
+
+// Tests memcpy API by making multiple memory allocations using AllocFs and
+// performing a sequence of copies from one allocation to the next,
+// using MemCpyFunc to specify dependencies.
+// Assumes that the first and the last allocations are accessible on host.
+template <typename MemcpyFuncT, typename... AllocFuncssT>
+void test(queue &Q, MemcpyFuncT MemCpyFunc,
+          std::tuple<AllocFuncssT...> AllocFs) {
+  constexpr std::size_t NAllocations = std::tuple_size_v<decltype(AllocFs)>;
+  static_assert(NAllocations > 1);
+
+  std::vector<std::shared_ptr<int>> PtrPipeline;
+  PtrPipeline.reserve(NAllocations);
+  std::apply([&](auto &&...Fs) { ((PtrPipeline.push_back(Fs())), ...); },
+             AllocFs);
+
+  std::iota(PtrPipeline[0].get(), PtrPipeline[0].get() + DataSize, 0);
+
+  // No dependencies for the first operation.
+  event LastEvent =
+      Q.memcpy(PtrPipeline[1].get(), PtrPipeline[0].get(), NumBytes);
+  for (int I = 1; I < NAllocations - 1; ++I) {
+    LastEvent = MemCpyFunc(Q, LastEvent, PtrPipeline[I + 1].get(),
+                           PtrPipeline[I].get(), NumBytes);
+  }
+
+  Q.wait();
+
+  int *ResultPtr = PtrPipeline.back().get();
+  for (int I = 0; I < DataSize; ++I)
+    assert(ResultPtr[I] == I);
+}
+
+template <bool ExplicitDeps, typename MemCpyFuncT>
+void runTestsForMemCpyFunc(MemCpyFuncT MemCpyFunc) {
+  // TODO: add in_order property here when ExplicitDeps == false once it is
----------------
KseniyaTikhomirova wrote:

nit: BTW there are places you use "TODO" and here is "TODO:", I used "TODO:" always, it shouldn't affect "grep" results later but would be nice to stick to the single style.

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


More information about the llvm-commits mailing list