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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flang/include/flang/Runtime/CUDA/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
terminator.Crash("'%s' failed with '%s'", #expr, name); \
}(expr)

namespace Fortran::runtime::cuf {
namespace Fortran::runtime::cuda {

void CUFRegisterAllocator();

Expand All @@ -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_
4 changes: 2 additions & 2 deletions flang/include/flang/Runtime/CUDA/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "flang/Runtime/entry-names.h"
#include <cstddef>

namespace Fortran::runtime::cuf {
namespace Fortran::runtime::cuda {

extern "C" {

Expand All @@ -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_
26 changes: 13 additions & 13 deletions flang/lib/Optimizer/Transforms/CufOpConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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.
Expand All @@ -137,19 +137,19 @@ 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,
fir::LLVMTypeConverter *typeConverter)
: 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());

Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions flang/runtime/CUDA/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "cuda.h"

namespace Fortran::runtime::cuf {
namespace Fortran::runtime::cuda {

void CUFRegisterAllocator() {
allocatorRegistry.Register(
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions flang/runtime/CUDA/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -25,4 +25,4 @@ void RTDEF(CUFFreeDesciptor)(

RT_EXT_API_GROUP_END
}
} // namespace Fortran::runtime::cuf
} // namespace Fortran::runtime::cuda
8 changes: 4 additions & 4 deletions flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)};
Expand All @@ -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)};
Expand All @@ -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)};
Expand Down
Loading