[flang-commits] [flang] [flang][cuda] Add entry point for alloc/free and simple copy (PR #109867)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Tue Sep 24 15:22:32 PDT 2024
================
@@ -8,19 +8,69 @@
#include "flang/Runtime/CUDA/memory.h"
#include "../terminator.h"
+#include "flang/Runtime/CUDA/common.h"
#include "cuda_runtime.h"
namespace Fortran::runtime::cuda {
extern "C" {
+void *RTDEF(CUFMemAlloc)(
+ std::size_t bytes, unsigned type, const char *sourceFile, int sourceLine) {
+ void *ptr;
+ if (bytes != 0) {
+ if (type == kMemTypeDevice) {
+ CUDA_REPORT_IF_ERROR(cudaMalloc((void **)&ptr, bytes));
+ } else if (type == kMemTypeManaged || type == kMemTypeUnified) {
+ CUDA_REPORT_IF_ERROR(
+ cudaMallocManaged((void **)&ptr, bytes, cudaMemAttachGlobal));
+ } else if (type == kMemTypePinned) {
+ CUDA_REPORT_IF_ERROR(cudaMallocHost((void **)&ptr, bytes));
+ } else {
+ Terminator terminator{sourceFile, sourceLine};
+ terminator.Crash("unsupported memory type");
+ }
+ }
+ return ptr;
+}
+
+void RTDEF(CUFMemFree)(
+ void *ptr, unsigned type, const char *sourceFile, int sourceLine) {
----------------
vzakhari wrote:
I think making it a no-op for null `ptr` may be a good idea.
https://github.com/llvm/llvm-project/pull/109867
More information about the flang-commits
mailing list