zoukankan      html  css  js  c++  java
  • 常用CULA实例

      CULA 安装包里包含了几个例子,用来显示如何使用CULA.这些例子放在‘examples’ 目录里.
    这里列出几个常用的,使用CULA函数的例子.  
    Initialization and Shutdown

    #include <cula.h>
    
    culaStatus s;
    
    s = culaInitialize();
    if(s != culaNoError)
    {
        printf("%s\n", culaGetErrorString(s));
        /* ... Error Handling ... */
    }
    
    /* ... Your code ... */
    
    culaShutdown();
    

     Argument Errors 

    #include <cula.h>
    
    culaStatus s;
    
    s = culaSgeqrf(-1, -1, NULL, -1, NULL); /* obviously wrong */
    if(s != culaNoError)
    {
        if(s == culaArgumentError)
            printf("Argument %d has an illegal value\n", culaGetErrorInfo());
        else
            printf("%s\n", culaGetErrorString(s));
    }
    

     Data Errors

    #include <cula.h>
    
    float* A = malloc(20*20*sizeof(float));
    memset(A, 0, 20*20*sizeof(float)); /* singular matrix, illegal for LU (getrf) */
    int ipiv[20];
    s = culaSgetrf(20, 20, A, 20, ipiv);
    if( s != culaNoError )
    {
        if( s == culaDataError )
            printf("Data error with code %d, please see LAPACK documentation\n",
                culaGetErrorInfo());
        else
            printf("%s\n", culaGetErrorString(s));
    }
    

     Printing Errors to the Console

    #include <cula.h>
    
    culaStatus s;
    int info;
    char buf[256];
    
    s = <cula function>;
    
    if( s != culaNoError )
    {
        info = culaGetErrorInfo();
        culaGetErrorInfoString(s, info, buf, sizeof(buf));
    
        printf("%s", buf);
    }
    

     使用 C++ 接口

    #include <cula.hpp>
    
    template<class T>
    void GenericLU(T* A, int N) // type of T will be determined by the compiler
    {
        std::vector<int> piv(N);
    
        // no need for type specifier - determined automatically on overloads
        culaStatus s = culaGetrf(N, N, A, N, &ipiv[0]);
    
        // check errors
    }
    

     检查有没有正确连接到库 

    #include <cula.h>
    
    int MeetsMinimumCulaRequirements()
    {
        int cudaMinimumVersion = culaGetCudaMinimumVersion();
        int cudaRuntimeVersion = culaGetCudaRuntimeVersion();
        int cudaDriverVersion = culaGetCudaDriverVersion();
        int cublasMinimumVersion = culaGetCublasMinimumVersion();
        int cublasRuntimeVersion = culaGetCublasRuntimeVersion();
    
        if(cudaRuntimeVersion < cudaMinimumVersion)
        {
            printf("CUDA runtime version is insufficient; "
                   "version %d or greater is required\n", cudaMinimumVersion);
            return 0;
        }
    
        if(cudaDriverVersion < cudaMinimumVersion)
        {
            printf("CUDA driver version is insufficient; "
                   "version %d or greater is required\n", cudaMinimumVersion);
            return 0;
        }
    
        if(cublasRuntimeVersion < cublasMinimumVersion)
        {
            printf("CUBLAS runtime version is insufficient; "
                   "version %d or greater is required\n", cublasMinimumVersion);
            return 0;
        }
    
        return 1;
    }
    
  • 相关阅读:
    WMI系统管理工具介绍和获取机器码
    QListWidget高性能加载图片数据
    2.5偏差方差分解
    QT图片旋转动画
    Qt实现数字滚动动画效果
    Qt动画使用总结
    线性回归--经验最小化,结构最小化,最大似然估计,最大后验估计
    获取国家2019年最新的省、市、区/县、街道、小区/居委会信息 包括港澳台
    .net 利用Emit将object转为DbParameter,DataTable转为List<>
    c#简单操作MongoDB_2.4
  • 原文地址:https://www.cnblogs.com/gpus/p/2478161.html
Copyright © 2011-2022 走看看