Skip to content

Commit 4c1dbbe

Browse files
authored
[flang][cuda] Make CUFRegisterAllocator callable from C/Fortran (llvm#102543)
1 parent 4a2bf05 commit 4c1dbbe

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

flang/include/flang/Runtime/CUDA/allocator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
1111

1212
#include "flang/Runtime/descriptor.h"
13+
#include "flang/Runtime/entry-names.h"
1314

1415
#define CUDA_REPORT_IF_ERROR(expr) \
1516
[](CUresult result) { \
@@ -25,7 +26,10 @@
2526

2627
namespace Fortran::runtime::cuda {
2728

28-
void CUFRegisterAllocator();
29+
extern "C" {
30+
31+
void RTDECL(CUFRegisterAllocator)();
32+
}
2933

3034
void *CUFAllocPinned(std::size_t);
3135
void CUFFreePinned(void *);

flang/runtime/CUDA/allocator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
#include "cuda.h"
1919

2020
namespace Fortran::runtime::cuda {
21+
extern "C" {
2122

22-
void CUFRegisterAllocator() {
23+
void RTDEF(CUFRegisterAllocator)() {
2324
allocatorRegistry.Register(
2425
kPinnedAllocatorPos, {&CUFAllocPinned, CUFFreePinned});
2526
allocatorRegistry.Register(
@@ -29,6 +30,7 @@ void CUFRegisterAllocator() {
2930
allocatorRegistry.Register(
3031
kUnifiedAllocatorPos, {&CUFAllocUnified, CUFFreeUnified});
3132
}
33+
}
3234

3335
void *CUFAllocPinned(std::size_t sizeInBytes) {
3436
void *p;

flang/unittests/Runtime/CUDA/AllocatorCUF.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ScopedContext {
5555

5656
TEST(AllocatableCUFTest, SimpleDeviceAllocate) {
5757
using Fortran::common::TypeCategory;
58-
Fortran::runtime::cuda::CUFRegisterAllocator();
58+
RTNAME(CUFRegisterAllocator)();
5959
ScopedContext ctx;
6060
// REAL(4), DEVICE, ALLOCATABLE :: a(:)
6161
auto a{createAllocatable(TypeCategory::Real, 4)};
@@ -73,7 +73,7 @@ TEST(AllocatableCUFTest, SimpleDeviceAllocate) {
7373

7474
TEST(AllocatableCUFTest, SimplePinnedAllocate) {
7575
using Fortran::common::TypeCategory;
76-
Fortran::runtime::cuda::CUFRegisterAllocator();
76+
RTNAME(CUFRegisterAllocator)();
7777
ScopedContext ctx;
7878
// INTEGER(4), PINNED, ALLOCATABLE :: a(:)
7979
auto a{createAllocatable(TypeCategory::Integer, 4)};
@@ -92,7 +92,7 @@ TEST(AllocatableCUFTest, SimplePinnedAllocate) {
9292

9393
TEST(AllocatableCUFTest, DescriptorAllocationTest) {
9494
using Fortran::common::TypeCategory;
95-
Fortran::runtime::cuda::CUFRegisterAllocator();
95+
RTNAME(CUFRegisterAllocator)();
9696
ScopedContext ctx;
9797
// REAL(4), DEVICE, ALLOCATABLE :: a(:)
9898
auto a{createAllocatable(TypeCategory::Real, 4)};

0 commit comments

Comments
 (0)