Skip to content

[flang][cuda][NFC] Disambiguate namespace with cuf dialect #102194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

clementval
Copy link
Contributor

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

@clementval clementval requested a review from wangzpgi August 6, 2024 18:34
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category flang:fir-hlfir labels Aug 6, 2024
Rename namespace `Fortran::runtime::cuf` to `Fortran::runtime::cuda`
to avoid embiguity with the namespace `::cuf` that is defined in the
CUF dialect.
@llvmbot
Copy link
Member

llvmbot commented Aug 6, 2024

@llvm/pr-subscribers-flang-runtime

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/102194.diff

6 Files Affected:

  • (modified) flang/include/flang/Runtime/CUDA/allocator.h (+2-2)
  • (modified) flang/include/flang/Runtime/CUDA/descriptor.h (+2-2)
  • (modified) flang/lib/Optimizer/Transforms/CufOpConversion.cpp (+13-13)
  • (modified) flang/runtime/CUDA/allocator.cpp (+2-2)
  • (modified) flang/runtime/CUDA/descriptor.cpp (+2-2)
  • (modified) flang/unittests/Runtime/CUDA/AllocatorCUF.cpp (+4-4)
diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/flang/include/flang/Runtime/CUDA/allocator.h
index 46ff5dbe2f3853..849785cf991ff2 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 33b993b219f297..d593989420420f 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 61c95843a34316..70b50379942161 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 26a3c296962690..08fae9efb3e9d6 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 e228c0f76aae09..1031b1e601b646 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 2355c47778cca7..4f53e654034cb7 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)};

@clementval clementval merged commit 10d7805 into llvm:main Aug 6, 2024
5 of 6 checks passed
@clementval clementval deleted the cuf_namespace branch August 6, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants