[flang-commits] [flang] [flang][cuda] Add new entry points function for data transfer (PR #108244)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Wed Sep 11 09:14:36 PDT 2024
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/108244
>From 968d2ddfdd648a2e34e53a9a662066688b7010c1 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 9 Sep 2024 15:15:17 -0700
Subject: [PATCH 1/2] [flang][cuda] Add runtime function for data transfer
---
flang/include/flang/Runtime/CUDA/memory.h | 45 +++++++++++++++++++++
flang/lib/Optimizer/Dialect/FIRType.cpp | 2 +-
flang/runtime/CUDA/CMakeLists.txt | 1 +
flang/runtime/CUDA/memory.cpp | 49 +++++++++++++++++++++++
4 files changed, 96 insertions(+), 1 deletion(-)
create mode 100644 flang/include/flang/Runtime/CUDA/memory.h
create mode 100644 flang/runtime/CUDA/memory.cpp
diff --git a/flang/include/flang/Runtime/CUDA/memory.h b/flang/include/flang/Runtime/CUDA/memory.h
new file mode 100644
index 00000000000000..39fd333152eb8e
--- /dev/null
+++ b/flang/include/flang/Runtime/CUDA/memory.h
@@ -0,0 +1,45 @@
+//===-- include/flang/Runtime/CUDA/memory.h ---------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef FORTRAN_RUNTIME_CUDA_MEMORY_H_
+#define FORTRAN_RUNTIME_CUDA_MEMORY_H_
+
+#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/entry-names.h"
+#include <cstddef>
+
+static constexpr unsigned kHostToDevice = 0;
+static constexpr unsigned kDeviceToHost = 1;
+static constexpr unsigned kDeviceToDevice = 2;
+
+namespace Fortran::runtime::cuda {
+
+extern "C" {
+
+// Set value to the data hold by a descriptor.
+void RTDECL(CUFMemsetDescriptor)(const Descriptor &desc, void* value,
+ const char *sourceFile = nullptr, int sourceLine = 0);
+
+// Data transfer from a pointer to a descriptor.
+void RTDECL(CUFDataTransferDescPtr)(const Descriptor &dst, void *src,
+ std::size_t bytes, unsigned mode, const char *sourceFile = nullptr,
+ int sourceLine = 0);
+
+// Data transfer from a descriptor to a pointer.
+void RTDECL(CUFDataTransferPtrDesc)(void *dst, const Descriptor &src,
+ std::size_t bytes, unsigned mode, const char *sourceFile = nullptr,
+ int sourceLine = 0);
+
+// Data transfer from a descriptor to a descriptor.
+void RTDECL(CUFDataTransferDescDesc)(const Descriptor &dst,
+ const Descriptor &src, unsigned mode, const char *sourceFile = nullptr,
+ int sourceLine = 0);
+
+} // extern "C"
+} // namespace Fortran::runtime::cuda
+#endif // FORTRAN_RUNTIME_CUDA_MEMORY_H_
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index c1debf28d00332..05f644654efe1b 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -1467,4 +1467,4 @@ fir::getTypeSizeAndAlignmentOrCrash(mlir::Location loc, mlir::Type ty,
if (result)
return *result;
TODO(loc, "computing size of a component");
-}
\ No newline at end of file
+}
diff --git a/flang/runtime/CUDA/CMakeLists.txt b/flang/runtime/CUDA/CMakeLists.txt
index 81055b2737c0f1..490bb369b572f6 100644
--- a/flang/runtime/CUDA/CMakeLists.txt
+++ b/flang/runtime/CUDA/CMakeLists.txt
@@ -16,6 +16,7 @@ set(CUFRT_LIBNAME CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR})
add_flang_library(${CUFRT_LIBNAME}
allocator.cpp
descriptor.cpp
+ memory.cpp
)
if (BUILD_SHARED_LIBS)
diff --git a/flang/runtime/CUDA/memory.cpp b/flang/runtime/CUDA/memory.cpp
new file mode 100644
index 00000000000000..34eee34762bec9
--- /dev/null
+++ b/flang/runtime/CUDA/memory.cpp
@@ -0,0 +1,49 @@
+//===-- runtime/CUDA/memory.cpp -------------------------------------------===//
+//
+// 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/Runtime/CUDA/memory.h"
+#include "../terminator.h"
+
+#include "cuda_runtime.h"
+
+namespace Fortran::runtime::cuda {
+extern "C" {
+
+void RTDEF(CUFMemsetDescriptor)(const Descriptor &desc, void* value,
+ const char *sourceFile, int sourceLine) {
+ Terminator terminator{sourceFile, sourceLine};
+ terminator.Crash(
+ "not yet implemented: CUDA data transfer from a scalar value to a descriptor");
+}
+
+void RTDEF(CUFDataTransferDescPtr)(const Descriptor &desc, void *addr,
+ std::size_t bytes, unsigned mode, const char *sourceFile,
+ int sourceLine) {
+ Terminator terminator{sourceFile, sourceLine};
+ terminator.Crash(
+ "not yet implemented: CUDA data transfer from a pointer to a descriptor");
+}
+
+void RTDEF(CUFDataTransferPtrDesc)(void* addr, const Descriptor &desc,
+ std::size_t bytes, unsigned mode, const char *sourceFile,
+ int sourceLine) {
+ Terminator terminator{sourceFile, sourceLine};
+ terminator.Crash(
+ "not yet implemented: CUDA data transfer from a descriptor to a pointer");
+}
+
+void RTDECL(CUFDataTransferDescDesc)(const Descriptor &dstDesc,
+ const Descriptor &srcDesc, unsigned mode, const char *sourceFile,
+ int sourceLine) {
+ Terminator terminator{sourceFile, sourceLine};
+ terminator.Crash(
+ "not yet implemented: CUDA data transfer between two descriptors");
+}
+
+}
+} // namespace Fortran::runtime::cuda
>From 4c5bc93c695105107b04562f4da4e10ca22a5246 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 11 Sep 2024 09:14:25 -0700
Subject: [PATCH 2/2] clang-format
---
flang/include/flang/Runtime/CUDA/memory.h | 2 +-
flang/runtime/CUDA/memory.cpp | 15 ++++++---------
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/flang/include/flang/Runtime/CUDA/memory.h b/flang/include/flang/Runtime/CUDA/memory.h
index 39fd333152eb8e..9aca4016e7e87a 100644
--- a/flang/include/flang/Runtime/CUDA/memory.h
+++ b/flang/include/flang/Runtime/CUDA/memory.h
@@ -22,7 +22,7 @@ namespace Fortran::runtime::cuda {
extern "C" {
// Set value to the data hold by a descriptor.
-void RTDECL(CUFMemsetDescriptor)(const Descriptor &desc, void* value,
+void RTDECL(CUFMemsetDescriptor)(const Descriptor &desc, void *value,
const char *sourceFile = nullptr, int sourceLine = 0);
// Data transfer from a pointer to a descriptor.
diff --git a/flang/runtime/CUDA/memory.cpp b/flang/runtime/CUDA/memory.cpp
index 34eee34762bec9..a287fa14a48789 100644
--- a/flang/runtime/CUDA/memory.cpp
+++ b/flang/runtime/CUDA/memory.cpp
@@ -14,24 +14,22 @@
namespace Fortran::runtime::cuda {
extern "C" {
-void RTDEF(CUFMemsetDescriptor)(const Descriptor &desc, void* value,
+void RTDEF(CUFMemsetDescriptor)(const Descriptor &desc, void *value,
const char *sourceFile, int sourceLine) {
Terminator terminator{sourceFile, sourceLine};
- terminator.Crash(
- "not yet implemented: CUDA data transfer from a scalar value to a descriptor");
+ terminator.Crash("not yet implemented: CUDA data transfer from a scalar "
+ "value to a descriptor");
}
void RTDEF(CUFDataTransferDescPtr)(const Descriptor &desc, void *addr,
- std::size_t bytes, unsigned mode, const char *sourceFile,
- int sourceLine) {
+ std::size_t bytes, unsigned mode, const char *sourceFile, int sourceLine) {
Terminator terminator{sourceFile, sourceLine};
terminator.Crash(
"not yet implemented: CUDA data transfer from a pointer to a descriptor");
}
-void RTDEF(CUFDataTransferPtrDesc)(void* addr, const Descriptor &desc,
- std::size_t bytes, unsigned mode, const char *sourceFile,
- int sourceLine) {
+void RTDEF(CUFDataTransferPtrDesc)(void *addr, const Descriptor &desc,
+ std::size_t bytes, unsigned mode, const char *sourceFile, int sourceLine) {
Terminator terminator{sourceFile, sourceLine};
terminator.Crash(
"not yet implemented: CUDA data transfer from a descriptor to a pointer");
@@ -44,6 +42,5 @@ void RTDECL(CUFDataTransferDescDesc)(const Descriptor &dstDesc,
terminator.Crash(
"not yet implemented: CUDA data transfer between two descriptors");
}
-
}
} // namespace Fortran::runtime::cuda
More information about the flang-commits
mailing list