blob: af09604865431862ec04f827ff792c52cbbed798 [file] [edit]
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
subroutine associated_stream
use cuda_runtime_api
integer(kind=cuda_stream_kind) :: strm, strmout
integer, managed, allocatable :: v(:)
integer :: istat
istat = cudaforSetDefaultStream(v, strm)
strmout = cudaforGetDefaultStream(v)
end subroutine
! CHECK-LABEL: func.func @_QPassociated_stream()
! CHECK: %[[ADDR:.*]] = fir.box_addr %{{.*}} : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
! CHECK: %[[STREAM:.*]] = fir.load %{{.*}}#0 : !fir.ref<i64>
! CHECK: %[[VOIDPTR:.*]] = fir.convert %[[ADDR]] : (!fir.heap<!fir.array<?xi32>>) -> !fir.llvm_ptr<i8>
! CHECK: %[[STAT:.*]] = fir.call @_FortranACUFSetAssociatedStream(%[[VOIDPTR]], %[[STREAM]]) fastmath<contract> : (!fir.llvm_ptr<i8>, i64) -> i32
! CHECK: hlfir.assign %[[STAT]] to %{{.*}}#0 : i32, !fir.ref<i32>
! CHECK: %[[ADDR:.*]] = fir.box_addr %{{.*}} : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
! CHECK: %[[VOIDPTR:.*]] = fir.convert %[[ADDR]] : (!fir.heap<!fir.array<?xi32>>) -> !fir.llvm_ptr<i8>
! CHECK: %[[STREAM:.*]] = fir.call @_FortranACUFGetAssociatedStream(%[[VOIDPTR]]) fastmath<contract> : (!fir.llvm_ptr<i8>) -> i64
! CHECK: hlfir.assign %[[STREAM]] to %{{.*}}#0 : i64, !fir.ref<i64>
subroutine default_stream
use cuda_runtime_api
integer(kind=cuda_stream_kind) :: strm, strm2
integer :: istat
istat = cudaStreamCreate(strm2)
istat = cudaforSetDefaultStream(strm2)
strm = cudaforGetDefaultStream()
istat = cudaStreamSynchronize(cudaforGetDefaultStream())
end subroutine
! CHECK-LABEL: func.func @_QPdefault_stream()
! CHECK: %{{.*}} = fir.call @_FortranACUFSetDefaultStream(%{{.*}}) fastmath<contract> : (i64) -> i32
! CHECK: %{{.*}} = fir.call @_FortranACUFGetDefaultStream() fastmath<contract> : () -> i64
! CHECK: %{{.*}} = fir.call @_FortranACUFGetDefaultStream() fastmath<contract> : () -> i64
subroutine stream_destroy
use cuda_runtime_api
integer(kind=cuda_stream_kind) :: strm
integer :: istat
istat = cudaStreamCreate(strm)
istat = cudaStreamDestroy(strm)
end subroutine
! CHECK-LABEL: func.func @_QPstream_destroy()
! CHECK: %{{.*}} = fir.call @_FortranACUFStreamDestroy(%{{.*}}) fastmath<contract> : (i64) -> i32
! A default-kind (i32) actual argument must be widened to i64 before
! reaching the runtime stream call.
subroutine default_stream_i32_literal
use cuda_runtime_api
integer :: istat
istat = cudaforSetDefaultStream(0)
istat = cudaStreamDestroy(0)
end subroutine
! CHECK-LABEL: func.func @_QPdefault_stream_i32_literal()
! CHECK: %[[ZERO1:.*]] = arith.constant 0 : i32
! CHECK: %[[STRM1:.*]] = fir.convert %[[ZERO1]] : (i32) -> i64
! CHECK: %{{.*}} = fir.call @_FortranACUFSetDefaultStream(%[[STRM1]]) fastmath<contract> : (i64) -> i32
! CHECK: %[[ZERO2:.*]] = arith.constant 0 : i32
! CHECK: %[[STRM2:.*]] = fir.convert %[[ZERO2]] : (i32) -> i64
! CHECK: %{{.*}} = fir.call @_FortranACUFStreamDestroy(%[[STRM2]]) fastmath<contract> : (i64) -> i32
subroutine default_stream_i32_var
use cuda_runtime_api
integer :: istat
integer(4) :: s
s = 0
istat = cudaforSetDefaultStream(s)
istat = cudaStreamDestroy(s)
end subroutine
! CHECK-LABEL: func.func @_QPdefault_stream_i32_var()
! CHECK: %[[L1:.*]] = fir.load %{{.*}} : !fir.ref<i32>
! CHECK: %[[V1:.*]] = fir.convert %[[L1]] : (i32) -> i64
! CHECK: %{{.*}} = fir.call @_FortranACUFSetDefaultStream(%[[V1]]) fastmath<contract> : (i64) -> i32
! CHECK: %[[L2:.*]] = fir.load %{{.*}} : !fir.ref<i32>
! CHECK: %[[V2:.*]] = fir.convert %[[L2]] : (i32) -> i64
! CHECK: %{{.*}} = fir.call @_FortranACUFStreamDestroy(%[[V2]]) fastmath<contract> : (i64) -> i32