@@ -149,6 +149,21 @@ static bool mustCastFuncOpToCopeWithImplicitInterfaceMismatch(
149
149
return false ;
150
150
}
151
151
152
+ static mlir::Value readDim3Value (fir::FirOpBuilder &builder, mlir::Location loc,
153
+ mlir::Value dim3Addr, llvm::StringRef comp) {
154
+ mlir::Type i32Ty = builder.getI32Type ();
155
+ mlir::Type refI32Ty = fir::ReferenceType::get (i32Ty);
156
+ llvm::SmallVector<mlir::Value> lenParams;
157
+
158
+ mlir::Value designate = builder.create <hlfir::DesignateOp>(
159
+ loc, refI32Ty, dim3Addr, /* component=*/ comp,
160
+ /* componentShape=*/ mlir::Value{}, hlfir::DesignateOp::Subscripts{},
161
+ /* substring=*/ mlir::ValueRange{}, /* complexPartAttr=*/ std::nullopt,
162
+ mlir::Value{}, lenParams);
163
+
164
+ return hlfir::loadTrivialScalar (loc, builder, hlfir::Entity{designate});
165
+ }
166
+
152
167
std::pair<fir::ExtendedValue, bool > Fortran::lower::genCallOpAndResult (
153
168
mlir::Location loc, Fortran::lower::AbstractConverter &converter,
154
169
Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx,
@@ -394,7 +409,67 @@ std::pair<fir::ExtendedValue, bool> Fortran::lower::genCallOpAndResult(
394
409
395
410
mlir::Value callResult;
396
411
unsigned callNumResults;
397
- if (caller.requireDispatchCall ()) {
412
+
413
+ if (!caller.getCallDescription ().chevrons ().empty ()) {
414
+ // A call to a CUDA kernel with the chevron syntax.
415
+
416
+ mlir::Type i32Ty = builder.getI32Type ();
417
+ mlir::Value one = builder.createIntegerConstant (loc, i32Ty, 1 );
418
+
419
+ mlir::Value grid_x, grid_y;
420
+ if (caller.getCallDescription ().chevrons ()[0 ].GetType ()->category () ==
421
+ Fortran::common::TypeCategory::Integer) {
422
+ // If grid is an integer, it is converted to dim3(grid,1,1). Since z is
423
+ // not used for the number of thread blocks, it is omitted in the op.
424
+ grid_x = builder.createConvert (
425
+ loc, i32Ty,
426
+ fir::getBase (converter.genExprValue (
427
+ caller.getCallDescription ().chevrons ()[0 ], stmtCtx)));
428
+ grid_y = one;
429
+ } else {
430
+ auto dim3Addr = converter.genExprAddr (
431
+ caller.getCallDescription ().chevrons ()[0 ], stmtCtx);
432
+ grid_x = readDim3Value (builder, loc, fir::getBase (dim3Addr), " x" );
433
+ grid_y = readDim3Value (builder, loc, fir::getBase (dim3Addr), " y" );
434
+ }
435
+
436
+ mlir::Value block_x, block_y, block_z;
437
+ if (caller.getCallDescription ().chevrons ()[1 ].GetType ()->category () ==
438
+ Fortran::common::TypeCategory::Integer) {
439
+ // If block is an integer, it is converted to dim3(block,1,1).
440
+ block_x = builder.createConvert (
441
+ loc, i32Ty,
442
+ fir::getBase (converter.genExprValue (
443
+ caller.getCallDescription ().chevrons ()[1 ], stmtCtx)));
444
+ block_y = one;
445
+ block_z = one;
446
+ } else {
447
+ auto dim3Addr = converter.genExprAddr (
448
+ caller.getCallDescription ().chevrons ()[1 ], stmtCtx);
449
+ block_x = readDim3Value (builder, loc, fir::getBase (dim3Addr), " x" );
450
+ block_y = readDim3Value (builder, loc, fir::getBase (dim3Addr), " y" );
451
+ block_z = readDim3Value (builder, loc, fir::getBase (dim3Addr), " z" );
452
+ }
453
+
454
+ mlir::Value bytes; // bytes is optional.
455
+ if (caller.getCallDescription ().chevrons ().size () > 2 )
456
+ bytes = builder.createConvert (
457
+ loc, i32Ty,
458
+ fir::getBase (converter.genExprValue (
459
+ caller.getCallDescription ().chevrons ()[2 ], stmtCtx)));
460
+
461
+ mlir::Value stream; // stream is optional.
462
+ if (caller.getCallDescription ().chevrons ().size () > 3 )
463
+ stream = builder.createConvert (
464
+ loc, i32Ty,
465
+ fir::getBase (converter.genExprValue (
466
+ caller.getCallDescription ().chevrons ()[3 ], stmtCtx)));
467
+
468
+ builder.create <fir::CUDAKernelLaunch>(
469
+ loc, funcType.getResults (), funcSymbolAttr, grid_x, grid_y, block_x,
470
+ block_y, block_z, bytes, stream, operands);
471
+ callNumResults = 0 ;
472
+ } else if (caller.requireDispatchCall ()) {
398
473
// Procedure call requiring a dynamic dispatch. Call is created with
399
474
// fir.dispatch.
400
475
0 commit comments