Add Fortran bindings
This commit is contained in:
committed by
Sylvain Jeaugey
parent
534b9a1697
commit
5f2b32e45b
@@ -0,0 +1,164 @@
|
||||
#ifndef _CUDA
|
||||
|
||||
!Start cudaFor module
|
||||
module cudaFor
|
||||
use iso_c_binding
|
||||
implicit none
|
||||
private
|
||||
public :: c_devptr
|
||||
public :: cudaMemcpyKind, &
|
||||
cudaMemcpyHostToHost, &
|
||||
cudaMemcpyHostToDevice, &
|
||||
cudaMemcpyDeviceToHost, &
|
||||
cudaMemcpyDeviceToDevice, &
|
||||
cudaMemcpyDefault
|
||||
public :: cuda_stream_kind
|
||||
public :: cudaGetDeviceCount
|
||||
public :: cudaSetDevice
|
||||
public :: cudaMalloc
|
||||
public :: cudaMemcpy
|
||||
public :: cudaFree
|
||||
public :: cudaStreamCreate
|
||||
public :: cudaStreamSynchronize
|
||||
public :: cudaStreamDestroy
|
||||
|
||||
!Start types
|
||||
|
||||
!Start c_devptr
|
||||
type, bind(c) :: c_devptr
|
||||
type(c_ptr) :: member
|
||||
end type c_devptr
|
||||
!End c_devptr
|
||||
|
||||
!Start cudaMemcpyKind
|
||||
type, bind(c) :: cudaMemcpyKind
|
||||
integer(c_int) :: member
|
||||
end type cudaMemcpyKind
|
||||
|
||||
type(cudaMemcpyKind), parameter :: cudaMemcpyHostToHost = cudaMemcpyKind(0), &
|
||||
cudaMemcpyHostToDevice = cudaMemcpyKind(1), &
|
||||
cudaMemcpyDeviceToHost = cudaMemcpyKind(2), &
|
||||
cudaMemcpyDeviceToDevice = cudaMemcpyKind(3), &
|
||||
cudaMemcpyDefault = cudaMemcpyKind(4)
|
||||
!End cudaMemcpyKind
|
||||
|
||||
!Start cuda_stream_kind
|
||||
integer(c_intptr_t), parameter :: cuda_stream_kind = c_intptr_t
|
||||
!End cuda_stream_kind
|
||||
|
||||
!End types
|
||||
|
||||
!Start interfaces
|
||||
|
||||
!Start cudaGetDeviceCount
|
||||
interface cudaGetDeviceCount
|
||||
integer(c_int) function cudaGetDeviceCount(count) bind(c, name = "cudaGetDeviceCount")
|
||||
import :: c_int
|
||||
implicit none
|
||||
integer(c_int) :: count
|
||||
end function cudaGetDeviceCount
|
||||
end interface cudaGetDeviceCount
|
||||
!End cudaGetDeviceCount
|
||||
|
||||
!Start cudaSetDevice
|
||||
interface cudaSetDevice
|
||||
integer(c_int) function cudaSetDevice(device) bind(c, name = "cudaSetDevice")
|
||||
import :: c_int
|
||||
implicit none
|
||||
integer(c_int), value :: device
|
||||
end function cudaSetDevice
|
||||
end interface cudaSetDevice
|
||||
!End cudaSetDevice
|
||||
|
||||
!Start cudaMalloc
|
||||
interface cudaMalloc
|
||||
integer(c_int) function cudaMalloc(devPtr, size) bind(c, name = "cudaMalloc")
|
||||
import :: c_int, c_size_t
|
||||
import :: c_devptr
|
||||
implicit none
|
||||
type(c_devptr) :: devPtr
|
||||
integer(c_size_t), value :: size
|
||||
end function cudaMalloc
|
||||
end interface cudaMalloc
|
||||
!End cudaMalloc
|
||||
|
||||
!Start cudaMemcpy
|
||||
interface cudaMemcpy
|
||||
|
||||
!Start cudaMemcpyH2D
|
||||
integer(c_int) function cudaMemcpyH2D(dst, src, count, kind) bind(c, name = "cudaMemcpy")
|
||||
import :: c_ptr, c_int, c_size_t
|
||||
import :: c_devptr, cudaMemcpyKind
|
||||
implicit none
|
||||
type(c_devptr), value :: dst
|
||||
type(c_ptr), value :: src
|
||||
integer(c_size_t), value :: count
|
||||
type(cudaMemcpyKind), value :: kind
|
||||
end function cudaMemcpyH2D
|
||||
!End cudaMemcpyH2D
|
||||
|
||||
!Start cudaMemcpyD2H
|
||||
integer(c_int) function cudaMemcpyD2H(dst, src, count, kind) bind(c, name = "cudaMemcpy")
|
||||
import :: c_ptr, c_int, c_size_t
|
||||
import :: c_devptr, cudaMemcpyKind
|
||||
implicit none
|
||||
type(c_ptr), value :: dst
|
||||
type(c_devptr), value :: src
|
||||
integer(c_size_t), value :: count
|
||||
type(cudaMemcpyKind), value :: kind
|
||||
end function cudaMemcpyD2H
|
||||
!End cudaMemcpyD2H
|
||||
|
||||
end interface cudaMemcpy
|
||||
!End cudaMemcpy
|
||||
|
||||
!Start cudaFree
|
||||
interface cudaFree
|
||||
integer(c_int) function cudaFree(devPtr) bind(c, name = "cudaFree")
|
||||
import :: c_int
|
||||
import :: c_devptr
|
||||
implicit none
|
||||
type(c_devptr), value :: devPtr
|
||||
end function cudaFree
|
||||
end interface cudaFree
|
||||
!End cudaFree
|
||||
|
||||
!Start cudaStreamCreate
|
||||
interface cudaStreamCreate
|
||||
integer(c_int) function cudaStreamCreate(pStream) bind(c, name = "cudaStreamCreate")
|
||||
import :: c_int
|
||||
import :: cuda_stream_kind
|
||||
implicit none
|
||||
integer(cuda_stream_kind) :: pStream
|
||||
end function cudaStreamCreate
|
||||
end interface cudaStreamCreate
|
||||
!End cudaStreamCreate
|
||||
|
||||
!Start cudaStreamSynchronize
|
||||
interface cudaStreamSynchronize
|
||||
integer(c_int) function cudaStreamSynchronize(stream) bind(c, name = "cudaStreamSynchronize")
|
||||
import :: c_int
|
||||
import :: cuda_stream_kind
|
||||
implicit none
|
||||
integer(cuda_stream_kind), value :: stream
|
||||
end function cudaStreamSynchronize
|
||||
end interface cudaStreamSynchronize
|
||||
!End cudaStreamSynchronize
|
||||
|
||||
!Start cudaStreamDestroy
|
||||
interface cudaStreamDestroy
|
||||
integer(c_int) function cudaStreamDestroy(stream) bind(c, name = "cudaStreamDestroy")
|
||||
import :: c_int
|
||||
import :: cuda_stream_kind
|
||||
implicit none
|
||||
integer(cuda_stream_kind), value :: stream
|
||||
end function cudaStreamDestroy
|
||||
end interface cudaStreamDestroy
|
||||
!End cudaStreamDestroy
|
||||
|
||||
!End interfaces
|
||||
|
||||
end module cudaFor
|
||||
!End cudaFor module
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,305 @@
|
||||
!Start defines
|
||||
#define NCCL_UNIQUE_ID_BYTES 128
|
||||
!End defines
|
||||
|
||||
!Start ncclFor module
|
||||
module ncclFor
|
||||
use iso_c_binding
|
||||
use cudaFor
|
||||
implicit none
|
||||
private
|
||||
public :: ncclUniqueId
|
||||
public :: ncclComm
|
||||
public :: ncclResult, &
|
||||
ncclSuccess, &
|
||||
ncclUnhandledCudaError, &
|
||||
ncclSystemError, &
|
||||
ncclInternalError, &
|
||||
ncclInvalidDevicePointer, &
|
||||
ncclInvalidRank, &
|
||||
ncclUnsupportedDeviceCount, &
|
||||
ncclDeviceNotFound, &
|
||||
ncclInvalidDeviceIndex, &
|
||||
ncclLibWrapperNotSet, &
|
||||
ncclCudaMallocFailed, &
|
||||
ncclRankMismatch, &
|
||||
ncclInvalidArgument, &
|
||||
ncclInvalidType, &
|
||||
ncclInvalidOperation, &
|
||||
nccl_NUM_RESULTS
|
||||
public :: ncclDataType, &
|
||||
ncclChar, &
|
||||
ncclInt, &
|
||||
#ifdef CUDA_HAS_HALF
|
||||
ncclHalf, &
|
||||
#endif
|
||||
ncclFloat, &
|
||||
ncclDouble, &
|
||||
ncclInt64, &
|
||||
ncclUInt64, &
|
||||
nccl_NUM_TYPES
|
||||
public :: ncclRedOp, &
|
||||
ncclSum, &
|
||||
ncclProd, &
|
||||
ncclMax, &
|
||||
ncclMin, &
|
||||
nccl_NUM_OPS
|
||||
public :: ncclGetUniqueId
|
||||
public :: ncclCommInitRank
|
||||
public :: ncclCommInitAll
|
||||
public :: ncclCommCuDevice
|
||||
public :: ncclCommUserRank
|
||||
public :: ncclCommCount
|
||||
public :: ncclCommDestroy
|
||||
public :: ncclReduce
|
||||
public :: ncclAllReduce
|
||||
public :: ncclReduceScatter
|
||||
public :: ncclBcast
|
||||
public :: ncclAllGather
|
||||
|
||||
!Start types
|
||||
|
||||
!Start ncclUniqueId
|
||||
type, bind(c) :: ncclUniqueId
|
||||
character(c_char) :: internal(NCCL_UNIQUE_ID_BYTES)
|
||||
end type ncclUniqueId
|
||||
!End ncclUniqueId
|
||||
|
||||
!Start ncclComm
|
||||
type, bind(c) :: ncclComm
|
||||
type(c_ptr) :: member
|
||||
end type ncclComm
|
||||
!End ncclComm
|
||||
|
||||
!Start ncclResult
|
||||
type, bind(c) :: ncclResult
|
||||
integer(c_int) :: member
|
||||
end type ncclResult
|
||||
|
||||
type(ncclResult), parameter :: ncclSuccess = ncclResult( 0), &
|
||||
ncclUnhandledCudaError = ncclResult( 1), &
|
||||
ncclSystemError = ncclResult( 2), &
|
||||
ncclInternalError = ncclResult( 3), &
|
||||
ncclInvalidDevicePointer = ncclResult( 4), &
|
||||
ncclInvalidRank = ncclResult( 5), &
|
||||
ncclUnsupportedDeviceCount = ncclResult( 6), &
|
||||
ncclDeviceNotFound = ncclResult( 7), &
|
||||
ncclInvalidDeviceIndex = ncclResult( 8), &
|
||||
ncclLibWrapperNotSet = ncclResult( 9), &
|
||||
ncclCudaMallocFailed = ncclResult(10), &
|
||||
ncclRankMismatch = ncclResult(11), &
|
||||
ncclInvalidArgument = ncclResult(12), &
|
||||
ncclInvalidType = ncclResult(13), &
|
||||
ncclInvalidOperation = ncclResult(14), &
|
||||
nccl_NUM_RESULTS = ncclResult(15)
|
||||
!End ncclResult
|
||||
|
||||
!Start ncclDataType
|
||||
type, bind(c) :: ncclDataType
|
||||
integer(c_int) :: member
|
||||
end type ncclDataType
|
||||
|
||||
type(ncclDataType), parameter :: ncclChar = ncclDataType(0), &
|
||||
ncclInt = ncclDataType(1), &
|
||||
#ifdef CUDA_HAS_HALF
|
||||
ncclHalf = ncclDataType(2), &
|
||||
#endif
|
||||
ncclFloat = ncclDataType(3), &
|
||||
ncclDouble = ncclDataType(4), &
|
||||
ncclInt64 = ncclDataType(5), &
|
||||
ncclUInt64 = ncclDataType(6), &
|
||||
nccl_NUM_TYPES = ncclDataType(7)
|
||||
!End ncclDataType
|
||||
|
||||
!Start ncclRedOp
|
||||
type, bind(c) :: ncclRedOp
|
||||
integer(c_int) :: member
|
||||
end type ncclRedOp
|
||||
|
||||
type(ncclRedOp), parameter :: ncclSum = ncclRedOp(0), &
|
||||
ncclProd = ncclRedOp(1), &
|
||||
ncclMax = ncclRedOp(2), &
|
||||
ncclMin = ncclRedOp(3), &
|
||||
nccl_NUM_OPS = ncclRedOp(4)
|
||||
!End ncclRedOp
|
||||
|
||||
!End types
|
||||
|
||||
!Start interfaces
|
||||
|
||||
!Start ncclGetUniqueId
|
||||
interface ncclGetUniqueId
|
||||
type(ncclResult) function ncclGetUniqueId(uniqueId) bind(c, name = 'ncclGetUniqueId')
|
||||
import :: ncclResult, ncclUniqueId
|
||||
implicit none
|
||||
type(ncclUniqueId) :: uniqueId
|
||||
end function ncclGetUniqueId
|
||||
end interface ncclGetUniqueId
|
||||
!End ncclGetUniqueId
|
||||
|
||||
!Start ncclCommInitRank
|
||||
interface ncclCommInitRank
|
||||
type(ncclResult) function ncclCommInitRank(comm, ndev, commId, rank) bind(c, name = 'ncclCommInitRank')
|
||||
import :: c_int
|
||||
import :: ncclResult, ncclUniqueId, ncclComm
|
||||
implicit none
|
||||
type(ncclComm) :: comm(*)
|
||||
integer(c_int), value :: ndev
|
||||
type(ncclUniqueId), value :: commId
|
||||
integer(c_int), value :: rank
|
||||
end function ncclCommInitRank
|
||||
end interface ncclCommInitRank
|
||||
!End ncclCommInitRank
|
||||
|
||||
!Start ncclCommInitAll
|
||||
interface ncclCommInitAll
|
||||
type(ncclResult) function ncclCommInitAll(comm, ndev, devlist) bind(c, name = 'ncclCommInitAll')
|
||||
import :: c_int
|
||||
import :: ncclResult, ncclComm
|
||||
implicit none
|
||||
type(ncclComm) :: comm(*)
|
||||
integer(c_int), value :: ndev
|
||||
integer(c_int) :: devlist(*)
|
||||
end function ncclCommInitAll
|
||||
end interface ncclCommInitAll
|
||||
!End ncclCommInitAll
|
||||
|
||||
!Start ncclCommCuDevice
|
||||
interface ncclCommCuDevice
|
||||
type(ncclResult) function ncclCommCuDevice(comm, devid) bind(c, name = 'ncclCommCuDevice')
|
||||
import :: c_int
|
||||
import :: ncclResult, ncclComm
|
||||
implicit none
|
||||
type(ncclComm), value :: comm
|
||||
integer(c_int) :: devid
|
||||
end function ncclCommCuDevice
|
||||
end interface ncclCommCuDevice
|
||||
!End ncclCommCuDevice
|
||||
|
||||
!Start ncclCommUserRank
|
||||
interface ncclCommUserRank
|
||||
type(ncclResult) function ncclCommUserRank(comm, rank) bind(c, name = 'ncclCommUserRank')
|
||||
import :: c_int
|
||||
import :: ncclResult, ncclComm
|
||||
implicit none
|
||||
type(ncclComm), value :: comm
|
||||
integer(c_int) :: rank
|
||||
end function ncclCommUserRank
|
||||
end interface ncclCommUserRank
|
||||
!End ncclCommUserRank
|
||||
|
||||
!Start ncclCommCount
|
||||
interface ncclCommCount
|
||||
type(ncclResult) function ncclCommCount(comm, count) bind(c, name = 'ncclCommCount')
|
||||
import :: c_int
|
||||
import :: ncclResult, ncclComm
|
||||
implicit none
|
||||
type(ncclComm), value :: comm
|
||||
integer(c_int) :: count
|
||||
end function ncclCommCount
|
||||
end interface ncclCommCount
|
||||
!End ncclCommCount
|
||||
|
||||
!Start ncclCommDestroy
|
||||
interface ncclCommDestroy
|
||||
subroutine ncclCommDestroy(comm) bind(c, name = 'ncclCommDestroy')
|
||||
import :: ncclComm
|
||||
implicit none
|
||||
type(ncclComm), value :: comm
|
||||
end subroutine ncclCommDestroy
|
||||
end interface ncclCommDestroy
|
||||
!End ncclCommDestroy
|
||||
|
||||
!Start ncclReduce
|
||||
interface ncclReduce
|
||||
type(ncclResult) function ncclReduce(sendbuff, recvbuff, count, datatype, op, root, comm, stream) bind(c, name = 'ncclReduce')
|
||||
import :: c_int
|
||||
import :: c_devptr, cuda_stream_kind
|
||||
import :: ncclResult, ncclComm, ncclDataType, ncclRedOp
|
||||
implicit none
|
||||
type(c_devptr), value :: sendbuff
|
||||
type(c_devptr), value :: recvbuff
|
||||
integer(c_int), value :: count
|
||||
type(ncclDataType), value :: datatype
|
||||
type(ncclRedOp), value :: op
|
||||
integer(c_int), value :: root
|
||||
type(ncclComm), value :: comm
|
||||
integer(cuda_stream_kind), value :: stream
|
||||
end function ncclReduce
|
||||
end interface ncclReduce
|
||||
!End ncclReduce
|
||||
|
||||
!Start ncclAllReduce
|
||||
interface ncclAllReduce
|
||||
type(ncclResult) function ncclAllReduce(sendbuff, recvbuff, count, datatype, op, comm, stream) bind(c, name = 'ncclAllReduce')
|
||||
import :: c_int
|
||||
import :: c_devptr, cuda_stream_kind
|
||||
import :: ncclResult, ncclComm, ncclDataType, ncclRedOp
|
||||
implicit none
|
||||
type(c_devptr), value :: sendbuff
|
||||
type(c_devptr), value :: recvbuff
|
||||
integer(c_int), value :: count
|
||||
type(ncclDataType), value :: datatype
|
||||
type(ncclRedOp), value :: op
|
||||
type(ncclComm), value :: comm
|
||||
integer(cuda_stream_kind), value :: stream
|
||||
end function ncclAllReduce
|
||||
end interface ncclAllReduce
|
||||
!End ncclAllReduce
|
||||
|
||||
!Start ncclReduceScatter
|
||||
interface ncclReduceScatter
|
||||
type(ncclResult) function ncclReduceScatter(sendbuff, recvbuff, recvcount, datatype, op, comm, stream) bind(c, name = 'ncclReduceScatter')
|
||||
import :: c_int
|
||||
import :: c_devptr, cuda_stream_kind
|
||||
import :: ncclResult, ncclComm, ncclDataType, ncclRedOp
|
||||
implicit none
|
||||
type(c_devptr), value :: sendbuff
|
||||
type(c_devptr), value :: recvbuff
|
||||
integer(c_int), value :: recvcount
|
||||
type(ncclDataType), value :: datatype
|
||||
type(ncclRedOp), value :: op
|
||||
type(ncclComm), value :: comm
|
||||
integer(cuda_stream_kind), value :: stream
|
||||
end function ncclReduceScatter
|
||||
end interface ncclReduceScatter
|
||||
!End ncclReduceScatter
|
||||
|
||||
!Start ncclBcast
|
||||
interface ncclBcast
|
||||
type(ncclResult) function ncclBcast(buff, count, datatype, root, comm, stream) bind(c, name = 'ncclBcast')
|
||||
import :: c_int
|
||||
import :: c_devptr, cuda_stream_kind
|
||||
import :: ncclResult, ncclComm, ncclDataType
|
||||
implicit none
|
||||
type(c_devptr), value :: buff
|
||||
integer(c_int), value :: count
|
||||
type(ncclDataType), value :: datatype
|
||||
integer(c_int), value :: root
|
||||
type(ncclComm), value :: comm
|
||||
integer(cuda_stream_kind), value :: stream
|
||||
end function ncclBcast
|
||||
end interface ncclBcast
|
||||
!End ncclBcast
|
||||
|
||||
!Start ncclAllGather
|
||||
interface ncclAllGather
|
||||
type(ncclResult) function ncclAllGather(sendbuff, count, datatype, recvbuff, comm, stream) bind(c, name = 'ncclAllGather')
|
||||
import :: c_int
|
||||
import :: c_devptr, cuda_stream_kind
|
||||
import :: ncclResult, ncclComm, ncclDataType
|
||||
implicit none
|
||||
type(c_devptr), value :: sendbuff
|
||||
integer(c_int), value :: count
|
||||
type(ncclDataType), value :: datatype
|
||||
type(c_devptr), value :: recvbuff
|
||||
type(ncclComm), value :: comm
|
||||
integer(cuda_stream_kind), value :: stream
|
||||
end function ncclAllGather
|
||||
end interface ncclAllGather
|
||||
!End ncclAllGather
|
||||
|
||||
!End interfaces
|
||||
|
||||
end module ncclFor
|
||||
!End nccl module
|
||||
Reference in New Issue
Block a user