Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ include "flang/Optimizer/Dialect/CUF/CUFDialect.td"
include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.td"
include "flang/Optimizer/Dialect/FIRTypes.td"
include "flang/Optimizer/Dialect/FIRAttr.td"
include "mlir/Dialect/GPU/IR/GPUBase.td"
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
include "mlir/Interfaces/LoopLikeInterface.td"
include "mlir/IR/BuiltinAttributes.td"
Expand Down Expand Up @@ -370,4 +371,25 @@ def cuf_SharedMemoryOp
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>];
}

def cuf_StreamCastOp : cuf_Op<"stream_cast", [NoMemoryEffect]> {
let summary = "Adapt a stream value to a GPU async token";

let description = [{
Cast a stream object reference as a GPU async token. This is useful to be
able to connect the stream representation of CUDA Fortran and the async
mechanism of the GPU dialect.
Later in the lowering this will becoming a no op.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

becoming -> become

}];

let arguments = (ins fir_ReferenceType:$stream);

let results = (outs GPU_AsyncToken:$token);

let assemblyFormat = [{
$stream attr-dict `:` type($stream)
}];

let hasVerifier = 1;
}

#endif // FORTRAN_DIALECT_CUF_CUF_OPS
2 changes: 1 addition & 1 deletion flang/include/flang/Optimizer/Support/InitFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace fir::support {
mlir::cf::ControlFlowDialect, mlir::func::FuncDialect, \
mlir::vector::VectorDialect, mlir::math::MathDialect, \
mlir::complex::ComplexDialect, mlir::DLTIDialect, cuf::CUFDialect, \
mlir::NVVM::NVVMDialect
mlir::NVVM::NVVMDialect, mlir::gpu::GPUDialect

#define FLANG_CODEGEN_DIALECT_LIST FIRCodeGenDialect, mlir::LLVM::LLVMDialect

Expand Down
11 changes: 11 additions & 0 deletions flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ void cuf::SharedMemoryOp::build(
result.addAttributes(attributes);
}

//===----------------------------------------------------------------------===//
// StreamCastOp
//===----------------------------------------------------------------------===//

llvm::LogicalResult cuf::StreamCastOp::verify() {
auto refTy = mlir::dyn_cast<fir::ReferenceType>(getStream().getType());
if (!refTy.getEleTy().isInteger(64))
return emitOpError("stream is expected to be a i64 reference");
return mlir::success();
}

// Tablegen operators

#define GET_OP_CLASSES
Expand Down
21 changes: 21 additions & 0 deletions flang/test/Fir/CUDA/cuda-stream.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: fir-opt --split-input-file %s | FileCheck %s

module attributes {gpu.container_module} {
gpu.module @cuda_device_mod {
gpu.func @_QMmod1Psub1() kernel {
gpu.return
}
}
func.func @_QMmod1Phost_sub() {
%0 = fir.alloca i64
%1 = arith.constant 1 : index
%asyncTok = cuf.stream_cast %0 : !fir.ref<i64>
gpu.launch_func [%asyncTok] @cuda_device_mod::@_QMmod1Psub1 blocks in (%1, %1, %1) threads in (%1, %1, %1) args() {cuf.proc_attr = #cuf.cuda_proc<grid_global>}
return
}
}

// CHECK-LABEL: func.func @_QMmod1Phost_sub()
// CHECK: %[[STREAM:.*]] = fir.alloca i64
// CHECK: %[[TOKEN:.*]] = cuf.stream_cast %[[STREAM]] : <i64>
// CHECK: gpu.launch_func [%[[TOKEN]]] @cuda_device_mod::@_QMmod1Psub1
2 changes: 0 additions & 2 deletions flang/tools/fir-opt/fir-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ int main(int argc, char **argv) {
#endif
DialectRegistry registry;
fir::support::registerDialects(registry);
registry.insert<mlir::gpu::GPUDialect>();
registry.insert<mlir::NVVM::NVVMDialect>();
fir::support::addFIRExtensions(registry);
return failed(MlirOptMain(argc, argv, "FIR modular optimizer driver\n",
registry));
Expand Down
Loading