Skip to content

Commit bc54e56

Browse files
authored
[flang][cuda] Add new entry points function for data transfer (#108244)
Add new entry points for more complex data transfer involving descriptors. These functions will be called when converting `cuf.data_transfer` operations.
1 parent f564a48 commit bc54e56

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===-- include/flang/Runtime/CUDA/memory.h ---------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_RUNTIME_CUDA_MEMORY_H_
10+
#define FORTRAN_RUNTIME_CUDA_MEMORY_H_
11+
12+
#include "flang/Runtime/descriptor.h"
13+
#include "flang/Runtime/entry-names.h"
14+
#include <cstddef>
15+
16+
static constexpr unsigned kHostToDevice = 0;
17+
static constexpr unsigned kDeviceToHost = 1;
18+
static constexpr unsigned kDeviceToDevice = 2;
19+
20+
namespace Fortran::runtime::cuda {
21+
22+
extern "C" {
23+
24+
/// Set value to the data hold by a descriptor. The \p value pointer must be
25+
/// addressable to the same amount of bytes specified by the element size of
26+
/// the descriptor \p desc.
27+
void RTDECL(CUFMemsetDescriptor)(const Descriptor &desc, void *value,
28+
const char *sourceFile = nullptr, int sourceLine = 0);
29+
30+
/// Data transfer from a pointer to a descriptor.
31+
void RTDECL(CUFDataTransferDescPtr)(const Descriptor &dst, void *src,
32+
std::size_t bytes, unsigned mode, const char *sourceFile = nullptr,
33+
int sourceLine = 0);
34+
35+
/// Data transfer from a descriptor to a pointer.
36+
void RTDECL(CUFDataTransferPtrDesc)(void *dst, const Descriptor &src,
37+
std::size_t bytes, unsigned mode, const char *sourceFile = nullptr,
38+
int sourceLine = 0);
39+
40+
/// Data transfer from a descriptor to a descriptor.
41+
void RTDECL(CUFDataTransferDescDesc)(const Descriptor &dst,
42+
const Descriptor &src, unsigned mode, const char *sourceFile = nullptr,
43+
int sourceLine = 0);
44+
45+
} // extern "C"
46+
} // namespace Fortran::runtime::cuda
47+
#endif // FORTRAN_RUNTIME_CUDA_MEMORY_H_

flang/lib/Optimizer/Dialect/FIRType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,4 +1467,4 @@ fir::getTypeSizeAndAlignmentOrCrash(mlir::Location loc, mlir::Type ty,
14671467
if (result)
14681468
return *result;
14691469
TODO(loc, "computing size of a component");
1470-
}
1470+
}

flang/runtime/CUDA/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(CUFRT_LIBNAME CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR})
1616
add_flang_library(${CUFRT_LIBNAME}
1717
allocator.cpp
1818
descriptor.cpp
19+
memory.cpp
1920
)
2021

2122
if (BUILD_SHARED_LIBS)

flang/runtime/CUDA/memory.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===-- runtime/CUDA/memory.cpp -------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "flang/Runtime/CUDA/memory.h"
10+
#include "../terminator.h"
11+
12+
#include "cuda_runtime.h"
13+
14+
namespace Fortran::runtime::cuda {
15+
extern "C" {
16+
17+
void RTDEF(CUFMemsetDescriptor)(const Descriptor &desc, void *value,
18+
const char *sourceFile, int sourceLine) {
19+
Terminator terminator{sourceFile, sourceLine};
20+
terminator.Crash("not yet implemented: CUDA data transfer from a scalar "
21+
"value to a descriptor");
22+
}
23+
24+
void RTDEF(CUFDataTransferDescPtr)(const Descriptor &desc, void *addr,
25+
std::size_t bytes, unsigned mode, const char *sourceFile, int sourceLine) {
26+
Terminator terminator{sourceFile, sourceLine};
27+
terminator.Crash(
28+
"not yet implemented: CUDA data transfer from a pointer to a descriptor");
29+
}
30+
31+
void RTDEF(CUFDataTransferPtrDesc)(void *addr, const Descriptor &desc,
32+
std::size_t bytes, unsigned mode, const char *sourceFile, int sourceLine) {
33+
Terminator terminator{sourceFile, sourceLine};
34+
terminator.Crash(
35+
"not yet implemented: CUDA data transfer from a descriptor to a pointer");
36+
}
37+
38+
void RTDECL(CUFDataTransferDescDesc)(const Descriptor &dstDesc,
39+
const Descriptor &srcDesc, unsigned mode, const char *sourceFile,
40+
int sourceLine) {
41+
Terminator terminator{sourceFile, sourceLine};
42+
terminator.Crash(
43+
"not yet implemented: CUDA data transfer between two descriptors");
44+
}
45+
}
46+
} // namespace Fortran::runtime::cuda

0 commit comments

Comments
 (0)