IMSL Fortran Math Library
CUBLAS_SET
Sets the switchover value for an array used by a specified BLAS routine.
Required Arguments
ENUM — An enumerator which specifies the BLAS routine for which the switchover value is to be set. (Input)
ENUM must be one of the values defined in Table 9.3, Table 9.4 or Table 9.5.
ARRAY_ARGUMENT — An integer indicating the array argument of the BLAS routine for which information is to be set. The array argument is specified by its position in the calling sequence, i.e. 1 = array argument 1, 2 = array argument 2, etc. (Input)
For example, for the BLAS routine SGEMM, array A is ARRAY_ARGUMENT = 1, array B is ARRAY_ARGUMENT = 2, and array C is ARRAY_ARGUMENT = 3.
NSTART — Defines the array size that is used as the swichover point for the array specified by ARRAY_ARGUMENT when the BLAS routine specified by ENUM is used. (Input)
For arrays  NSTART the NVIDIA device will be used. For arrays < NSTART a standard Fortran BLAS routine will be used. Setting NSTART to a negative value indicates that no array copy need be performed for the array specified by ARRAY_ARGUMENT. Setting NSTART to 0 indicates that the NVIDIA hardware in not used for the specified BLAS routine.
FORTRAN 90 Interface
Generic: CALL CUBLAS_SET (ENUM, ARRAY_ARGUMENT, NSTART)
Description
This routine allows the user to set the array size values that will be used by a specified BLAS routine as the switchover point for using a standard Fortran Blas routine versus the CUDABLAS routine with the NVIDIA device. The routine can also be used to inform the NVIDIA device to not perform an array copy after the initial copy has been performed.
Example
In this example the switchover for array A of the BLAS routine SGEMM is first retrieved by making a call to CUBLAS_GET. Then CUBLAS_SET is used to inform CUDABLAS_SGEMM not to copy array A from the CPU to the GPU after the initial copy. Then, CUBLAS_SET is used to reset the switchover value back to its original setting. Finally, CUBLAS_GET is used to query whether or not the NVIDIA device was used on the last call to SGEMM.
 
USE CUDABLAS_LIBRARY
USE UMACH_INT
INTEGER ARRAY_ARGUMENT, IDEVICE, ISWITCH, NOUT
INTEGER, PARAMETER :: N=500
REAL ALPHA, BETA, A(N,N), B(N,N), C(N,N), D(N,N)
 
ALPHA = 1.0
BETA = 1.0
A = 2.0
B = 3.0
C = 4.0
! ARRAY A IS THE FIRST ARRAY IN
! THE SGEMM CALLING SEQUENCE
ARRAY_ARGUMENT = 1
! GET THE CURRENT SWITCHOVER VALUE
! FOR SGEMM
 
ISWITCH = CUBLAS_GET (CUDABLAS_SGEMM, ARRAY_ARGUMENT)
! PERFORM AN ARRAY MULITIPLICATION
 
CALL SGEMM ('N', 'N', N, N, N, ALPHA, A, N, B, N, BETA, D, N)
 
! AVOID COPYING A FROM THE CPU TO
! THE GPU HENCEFORTH
 
CALL CUBLAS_SET (CUDABLAS_SGEMM, ARRAY_ARGUMENT, -ABS(ISWITCH))
 
! PERFORM A SECOND ARRAY MULTIPLICATION
 
CALL SGEMM ('N', 'N', N, N, N, ALPHA, A, N, C, N, BETA, C, N)
! RESET THE SWITCHOVER VALUE FOR
! SGEMM BACK TO ITS ORIGINAL VALUE
 
CALL CUBLAS_SET (CUDABLAS_SGEMM, ARRAY_ARGUMENT, ISWITCH)
! DETERMINE WHETHER OR NOT THE GPU
! WAS USED FOR THE LAST SGEMM CALL
ARRAY_ARGUMENT = 4
IDEVICE = CUBLAS_GET (CUDABLAS_SGEMM, ARRAY_ARGUMENT)
 
! PRINT THE RESULT OF THE LAST QUERY
CALL UMACH (2, NOUT)
IF (IDEVICE .EQ. 0) THEN
WRITE(NOUT, *)'THE STANDARD FORTRAN BLAS SGEMM WAS USED.'
ELSE
WRITE(NOUT, *)'THE NVIDIA DEVICE SGEMM WAS USED.'
END IF
END
Output
 
The NVIDIA DEVICE SGEMM WAS USED.