[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:21:01 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;
----------------
vzakhari wrote:
This will return an uninitialized pointer. I think `nullptr` should be the right default initialization.
https://github.com/llvm/llvm-project/pull/109867
More information about the flang-commits
mailing list