[flang-commits] [flang] [flang][cuda][NFC] Disambiguate namespace with cuf dialect (PR #102194)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Tue Aug 6 11:34:49 PDT 2024


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/102194

Rename namespace `Fortran::runtime::cuf` to `Fortran::runtime::cuda` to avoid embiguity with the namespace `::cuf` that is defined in the CUF dialect.

>From 40a26dfcffea919ac613f29da84669754bf9b495 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 6 Aug 2024 11:18:02 -0700
Subject: [PATCH] [flang][cuda][NFC] Disambiguate namesssssspace with cuf
 dialect

Rename namespace `Fortran::runtime::cuf` to `Fortran::runtime::cuda`
to avoid embiguity with the namespace `::cuf` that is defined in the
CUF dialect.
---
 flang/include/flang/Runtime/CUDA/allocator.h  |  4 +--
 flang/include/flang/Runtime/CUDA/descriptor.h |  4 +--
 .../Optimizer/Transforms/CufOpConversion.cpp  | 26 +++++++++----------
 flang/runtime/CUDA/allocator.cpp              |  4 +--
 flang/runtime/CUDA/descriptor.cpp             |  4 +--
 flang/unittests/Runtime/CUDA/AllocatorCUF.cpp |  8 +++---
 6 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/flang/include/flang/Runtime/CUDA/allocator.h
index 46ff5dbe2f385..849785cf991ff 100644
--- a/flang/include/flang/Runtime/CUDA/allocator.h
+++ b/flang/include/flang/Runtime/CUDA/allocator.h
@@ -23,7 +23,7 @@
     terminator.Crash("'%s' failed with '%s'", #expr, name); \
   }(expr)
 
-namespace Fortran::runtime::cuf {
+namespace Fortran::runtime::cuda {
 
 void CUFRegisterAllocator();
 
@@ -36,5 +36,5 @@ void CUFFreeDevice(void *);
 void *CUFAllocManaged(std::size_t);
 void CUFFreeManaged(void *);
 
-} // namespace Fortran::runtime::cuf
+} // namespace Fortran::runtime::cuda
 #endif // FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
diff --git a/flang/include/flang/Runtime/CUDA/descriptor.h b/flang/include/flang/Runtime/CUDA/descriptor.h
index 33b993b219f29..d593989420420 100644
--- a/flang/include/flang/Runtime/CUDA/descriptor.h
+++ b/flang/include/flang/Runtime/CUDA/descriptor.h
@@ -13,7 +13,7 @@
 #include "flang/Runtime/entry-names.h"
 #include <cstddef>
 
-namespace Fortran::runtime::cuf {
+namespace Fortran::runtime::cuda {
 
 extern "C" {
 
@@ -26,5 +26,5 @@ void RTDECL(CUFFreeDesciptor)(
     Descriptor *, const char *sourceFile = nullptr, int sourceLine = 0);
 
 } // extern "C"
-} // namespace Fortran::runtime::cuf
+} // namespace Fortran::runtime::cuda
 #endif // FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
diff --git a/flang/lib/Optimizer/Transforms/CufOpConversion.cpp b/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
index 61c95843a3431..70b5037994216 100644
--- a/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
@@ -28,7 +28,7 @@ namespace fir {
 using namespace fir;
 using namespace mlir;
 using namespace Fortran::runtime;
-using namespace Fortran::runtime::cuf;
+using namespace Fortran::runtime::cuda;
 
 namespace {
 
@@ -79,11 +79,11 @@ static mlir::LogicalResult convertOpToCall(OpTy op,
 }
 
 struct CufAllocateOpConversion
-    : public mlir::OpRewritePattern<::cuf::AllocateOp> {
+    : public mlir::OpRewritePattern<cuf::AllocateOp> {
   using OpRewritePattern::OpRewritePattern;
 
   mlir::LogicalResult
-  matchAndRewrite(::cuf::AllocateOp op,
+  matchAndRewrite(cuf::AllocateOp op,
                   mlir::PatternRewriter &rewriter) const override {
     // TODO: Allocation with source will need a new entry point in the runtime.
     if (op.getSource())
@@ -112,16 +112,16 @@ struct CufAllocateOpConversion
     mlir::func::FuncOp func =
         fir::runtime::getRuntimeFunc<mkRTKey(AllocatableAllocate)>(loc,
                                                                    builder);
-    return convertOpToCall<::cuf::AllocateOp>(op, rewriter, func);
+    return convertOpToCall<cuf::AllocateOp>(op, rewriter, func);
   }
 };
 
 struct CufDeallocateOpConversion
-    : public mlir::OpRewritePattern<::cuf::DeallocateOp> {
+    : public mlir::OpRewritePattern<cuf::DeallocateOp> {
   using OpRewritePattern::OpRewritePattern;
 
   mlir::LogicalResult
-  matchAndRewrite(::cuf::DeallocateOp op,
+  matchAndRewrite(cuf::DeallocateOp op,
                   mlir::PatternRewriter &rewriter) const override {
     // TODO: Allocation of module variable will need more work as the descriptor
     // will be duplicated and needs to be synced after allocation.
@@ -137,11 +137,11 @@ struct CufDeallocateOpConversion
     mlir::func::FuncOp func =
         fir::runtime::getRuntimeFunc<mkRTKey(AllocatableDeallocate)>(loc,
                                                                      builder);
-    return convertOpToCall<::cuf::DeallocateOp>(op, rewriter, func);
+    return convertOpToCall<cuf::DeallocateOp>(op, rewriter, func);
   }
 };
 
-struct CufAllocOpConversion : public mlir::OpRewritePattern<::cuf::AllocOp> {
+struct CufAllocOpConversion : public mlir::OpRewritePattern<cuf::AllocOp> {
   using OpRewritePattern::OpRewritePattern;
 
   CufAllocOpConversion(mlir::MLIRContext *context, mlir::DataLayout *dl,
@@ -149,7 +149,7 @@ struct CufAllocOpConversion : public mlir::OpRewritePattern<::cuf::AllocOp> {
       : OpRewritePattern(context), dl{dl}, typeConverter{typeConverter} {}
 
   mlir::LogicalResult
-  matchAndRewrite(::cuf::AllocOp op,
+  matchAndRewrite(cuf::AllocOp op,
                   mlir::PatternRewriter &rewriter) const override {
     auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(op.getInType());
 
@@ -187,11 +187,11 @@ struct CufAllocOpConversion : public mlir::OpRewritePattern<::cuf::AllocOp> {
   fir::LLVMTypeConverter *typeConverter;
 };
 
-struct CufFreeOpConversion : public mlir::OpRewritePattern<::cuf::FreeOp> {
+struct CufFreeOpConversion : public mlir::OpRewritePattern<cuf::FreeOp> {
   using OpRewritePattern::OpRewritePattern;
 
   mlir::LogicalResult
-  matchAndRewrite(::cuf::FreeOp op,
+  matchAndRewrite(cuf::FreeOp op,
                   mlir::PatternRewriter &rewriter) const override {
     // Only convert cuf.free on descriptor.
     if (!mlir::isa<fir::ReferenceType>(op.getDevptr().getType()))
@@ -235,8 +235,8 @@ class CufOpConversion : public fir::impl::CufOpConversionBase<CufOpConversion> {
     fir::LLVMTypeConverter typeConverter(module, /*applyTBAA=*/false,
                                          /*forceUnifiedTBAATree=*/false, *dl);
 
-    target.addIllegalOp<::cuf::AllocOp, ::cuf::AllocateOp, ::cuf::DeallocateOp,
-                        ::cuf::FreeOp>();
+    target.addIllegalOp<cuf::AllocOp, cuf::AllocateOp, cuf::DeallocateOp,
+                        cuf::FreeOp>();
     patterns.insert<CufAllocOpConversion>(ctx, &*dl, &typeConverter);
     patterns.insert<CufAllocateOpConversion, CufDeallocateOpConversion,
                     CufFreeOpConversion>(ctx);
diff --git a/flang/runtime/CUDA/allocator.cpp b/flang/runtime/CUDA/allocator.cpp
index 26a3c29696269..08fae9efb3e9d 100644
--- a/flang/runtime/CUDA/allocator.cpp
+++ b/flang/runtime/CUDA/allocator.cpp
@@ -17,7 +17,7 @@
 
 #include "cuda.h"
 
-namespace Fortran::runtime::cuf {
+namespace Fortran::runtime::cuda {
 
 void CUFRegisterAllocator() {
   allocatorRegistry.Register(
@@ -57,4 +57,4 @@ void CUFFreeManaged(void *p) {
   CUDA_REPORT_IF_ERROR(cuMemFree(reinterpret_cast<CUdeviceptr>(p)));
 }
 
-} // namespace Fortran::runtime::cuf
+} // namespace Fortran::runtime::cuda
diff --git a/flang/runtime/CUDA/descriptor.cpp b/flang/runtime/CUDA/descriptor.cpp
index e228c0f76aae0..1031b1e601b64 100644
--- a/flang/runtime/CUDA/descriptor.cpp
+++ b/flang/runtime/CUDA/descriptor.cpp
@@ -9,7 +9,7 @@
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/allocator.h"
 
-namespace Fortran::runtime::cuf {
+namespace Fortran::runtime::cuda {
 extern "C" {
 RT_EXT_API_GROUP_BEGIN
 
@@ -25,4 +25,4 @@ void RTDEF(CUFFreeDesciptor)(
 
 RT_EXT_API_GROUP_END
 }
-} // namespace Fortran::runtime::cuf
+} // namespace Fortran::runtime::cuda
diff --git a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp b/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
index 2355c47778cca..4f53e654034cb 100644
--- a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
@@ -17,7 +17,7 @@
 #include "cuda.h"
 
 using namespace Fortran::runtime;
-using namespace Fortran::runtime::cuf;
+using namespace Fortran::runtime::cuda;
 
 static OwningPtr<Descriptor> createAllocatable(
     Fortran::common::TypeCategory tc, int kind, int rank = 1) {
@@ -55,7 +55,7 @@ class ScopedContext {
 
 TEST(AllocatableCUFTest, SimpleDeviceAllocate) {
   using Fortran::common::TypeCategory;
-  Fortran::runtime::cuf::CUFRegisterAllocator();
+  Fortran::runtime::cuda::CUFRegisterAllocator();
   ScopedContext ctx;
   // REAL(4), DEVICE, ALLOCATABLE :: a(:)
   auto a{createAllocatable(TypeCategory::Real, 4)};
@@ -73,7 +73,7 @@ TEST(AllocatableCUFTest, SimpleDeviceAllocate) {
 
 TEST(AllocatableCUFTest, SimplePinnedAllocate) {
   using Fortran::common::TypeCategory;
-  Fortran::runtime::cuf::CUFRegisterAllocator();
+  Fortran::runtime::cuda::CUFRegisterAllocator();
   ScopedContext ctx;
   // INTEGER(4), PINNED, ALLOCATABLE :: a(:)
   auto a{createAllocatable(TypeCategory::Integer, 4)};
@@ -92,7 +92,7 @@ TEST(AllocatableCUFTest, SimplePinnedAllocate) {
 
 TEST(AllocatableCUFTest, DescriptorAllocationTest) {
   using Fortran::common::TypeCategory;
-  Fortran::runtime::cuf::CUFRegisterAllocator();
+  Fortran::runtime::cuda::CUFRegisterAllocator();
   ScopedContext ctx;
   // REAL(4), DEVICE, ALLOCATABLE :: a(:)
   auto a{createAllocatable(TypeCategory::Real, 4)};



More information about the flang-commits mailing list