@@ -3247,4 +3247,58 @@ def fir_CUDADeallocateOp : fir_Op<"cuda_deallocate",
3247
3247
let hasVerifier = 1;
3248
3248
}
3249
3249
3250
+ def fir_CUDAAllocOp : fir_Op<"cuda_alloc", [AttrSizedOperandSegments,
3251
+ MemoryEffects<[MemAlloc]>]> {
3252
+ let summary = "Allocate an object on device";
3253
+
3254
+ let description = [{
3255
+ This is a drop in replacement for fir.alloca and fir.allocmem for device
3256
+ object. Any device, managed or unified object declared in an host
3257
+ subprogram needs to be allocated in the device memory through runtime calls.
3258
+ The fir.cuda_alloc is an abstraction to the runtime calls and works together
3259
+ with fir.cuda_free.
3260
+ }];
3261
+
3262
+ let arguments = (ins
3263
+ TypeAttr:$in_type,
3264
+ OptionalAttr<StrAttr>:$uniq_name,
3265
+ OptionalAttr<StrAttr>:$bindc_name,
3266
+ Variadic<AnyIntegerType>:$typeparams,
3267
+ Variadic<AnyIntegerType>:$shape,
3268
+ fir_CUDADataAttributeAttr:$cuda_attr
3269
+ );
3270
+
3271
+ let results = (outs fir_ReferenceType:$ptr);
3272
+
3273
+ let assemblyFormat = [{
3274
+ $in_type (`(` $typeparams^ `:` type($typeparams) `)`)?
3275
+ (`,` $shape^ `:` type($shape) )? attr-dict `->` qualified(type($ptr))
3276
+ }];
3277
+
3278
+ let builders = [
3279
+ OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName,
3280
+ "llvm::StringRef":$bindcName,
3281
+ "fir::CUDADataAttributeAttr":$cudaAttr,
3282
+ CArg<"mlir::ValueRange", "{}">:$typeparams,
3283
+ CArg<"mlir::ValueRange", "{}">:$shape,
3284
+ CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>];
3285
+ }
3286
+
3287
+ def fir_CUDAFreeOp : fir_Op<"cuda_free", [MemoryEffects<[MemFree]>]> {
3288
+ let summary = "Free a device allocated object";
3289
+
3290
+ let description = [{
3291
+ The fir.cuda_free operation frees the memory allocated by fir.cuda_alloc.
3292
+ This is used for non-allocatable device, managed and unified device
3293
+ variables declare in host subprogram.
3294
+ }];
3295
+
3296
+ let arguments = (ins
3297
+ Arg<AnyReferenceLike, "", [MemFree]>:$devptr,
3298
+ fir_CUDADataAttributeAttr:$cuda_attr
3299
+ );
3300
+
3301
+ let assemblyFormat = "$devptr `:` qualified(type($devptr)) attr-dict";
3302
+ }
3303
+
3250
3304
#endif
0 commit comments