[flang-commits] [flang] [llvm] [flang-rt] Add Assign_omp RT call. (PR #145465)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Tue Aug 19 09:10:58 PDT 2025


================
@@ -0,0 +1,77 @@
+//===-- lib/runtime/assign_omp.cpp ----------------------------------*- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang-rt/runtime/assign-impl.h"
+#include "flang-rt/runtime/derived.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/type-info.h"
+#include "flang/Runtime/assign.h"
+
+#include <omp.h>
+
+namespace Fortran::runtime {
+namespace omp {
+
+typedef int32_t OMPDeviceTy;
+
+template <typename T> static T *getDevicePtr(T *anyPtr, OMPDeviceTy ompDevice) {
+  auto voidAnyPtr = reinterpret_cast<void *>(anyPtr);
+  // If not present on the device it should already be a device ptr
+  if (!omp_target_is_present(voidAnyPtr, ompDevice))
+    return anyPtr;
+  T *device_ptr = omp_get_mapped_ptr(anyPtr, ompDevice);
+  return device_ptr;
+}
+
+RT_API_ATTRS static void Assign(Descriptor &to, const Descriptor &from,
+    Terminator &terminator, int flags, OMPDeviceTy omp_device) {
+  std::size_t toElementBytes{to.ElementBytes()};
+  std::size_t fromElementBytes{from.ElementBytes()};
+  std::size_t toElements{to.Elements()};
+  std::size_t fromElements{from.Elements()};
----------------
clementval wrote:

If you want it to work also on non contiguous descriptors, the Assign function as a mechanism to pass  memmove function to use. 

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


More information about the flang-commits mailing list