IMSL C Math Library
cuda_get
Gets the threshold used by the specified function to determine if the NVIDIA CUDA Toolkit algorithm will be used.
Synopsis
#include <imsl.h>
int imsl_cuda_get (Imsl_cuda cuda_name)
Required Arguments
Imsl_cuda cuda_name (Input)
An enumerator which specifies the IMSL function for which the threshold will be retrieved. cuda_name must be one of the values defined in Table 12.9.
Return Value
Returns the threshold value used to determine when the NVIDIA CUDA Toolkit version of the function specified by cuda_name will be used. A return value of zero indicates that the IMSL version of the specified function will always be used. A return value greater than zero is the threshold value being used by the function specified by cuda_name. If the problem size is greater than or equal to threshold, the NVIDIA Toolkit algorithm will be used.
See Programming Notes for Using NVIDIA® CUDA™ Toolkit for more information on NVIDIA’s CUDA Toolkit integration into IMSL C Numerical Library.
Synopsis with Optional Arguments
#include <imsl.h>
int imsl_cuda_get (Imsl_cuda cuda_name,
IMSL_GET_DEVICE, int *idevice,
0)
Optional Arguments
IMSL_GET_DEVICE, int *idevice (Output)
Returns a value specifying whether the NVIDIA CUDA Toolkit algorithm was used for the last call to the IMSL function specified by cuda_name. Returns 1 if the NVIDIA Toolkit algorithm was used and 0 if the IMSL version of the algorithm was used. A value of 1 indicates that the IMSL function specified by cuda_name has not been used.
Description
This function returns the threshold value for a specified function. It can optionally be used to return information on the last invocation of the specified function.
Example
Function imsl_f_lin_sol_gen uses Basic Linear Algebra Subprogram SGER to improve performance. In this example the threshold value of the function SGER is manipulated to force the use of both the IMSL and NVIDIA CUDA Toolkit algorithms.
 
#include <imsl.h>
#include <stdio.h>
 
int main() {
    int    n = 3, iswitch, idevice;
    float  *x;
 
    float   lv_a[] =
    {
        1.0, 3.0, 3.0,
        1.0, 3.0, 4.0,
        1.0, 4.0, 3.0
    };
 
    float   lv_b[] =
    {
        1.0, 4.0, -1.0
    };
 
    /* Get the current threshold value for SGER */
    iswitch = imsl_cuda_get(IMSL_CUDA_SGER,0);
 
    /* Set the threshold value of SGER to 0
    so that use of the IMSL version is ensured */
    imsl_cuda_set(IMSL_CUDA_SGER, 0, 0);
 
    /* Call routine which uses SGER */
    x = imsl_f_lin_sol_gen (n, lv_a, lv_b, 0);
    imsl_free(x);
 
    /* Check to see what version of SGER was used */
    imsl_cuda_get(IMSL_CUDA_SGER,
        IMSL_GET_DEVICE, &idevice,
        0);
 
    if (!idevice)
        printf("The IMSL version of SGER was used.\n");
    else
        printf("Error: The CUDA version of SGER was used.\n");
 
    /* Set the threshold value to be very small to ensure the
    CUDA version of SGER will be used. */
    imsl_cuda_set(IMSL_CUDA_SGER, 1, 0);
 
    /* Call routine which uses SGER */
    x = imsl_f_lin_sol_gen(n, lv_a, lv_b, 0);
    imsl_free(x);
 
    /* Check to see what version of SGER */
    imsl_cuda_get(IMSL_CUDA_SGER,
        IMSL_GET_DEVICE, &idevice,
        0);
 
    if (!idevice)
        printf("Error:  The IMSL version of SGER was used.\n");
    else
        printf("The CUDA version of SGER was used.\n");
 
    /* Set the threshold value to the original setting */
    imsl_cuda_set(IMSL_CUDA_SGER, iswitch, 0);
 
    /* Release GPU memory */
    imsl_cuda_free();
}
Output
 
The IMSL version of SGEMM was used.
The CUDA version of SGEMM was used.
Warning Errors
IMSL_CUDA_ENUM_NAME
The argument specified for “cuda_name” = # is not valid.
IMSL_CUDA_NOT_IMPLEMENTED
The specified function name does not have a CUDA implementation.
IMSL_FCN_NOT_USED
The specified function name has not yet been used.
IMSL_CUDA_NOT_AVAIL
The CUDA Toolkit algorithms are not implemented using this version of the library. Use the CUDA link environment variables to leverage the CUDA Toolkit algorithms.