在Visual Studio C ++项目中使用尖峰 [英] Using cusp in a Visual Studio C++ project

查看:347
本文介绍了在Visual Studio C ++项目中使用尖峰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2012 Ultimate上使用cusp v.0.4.0,cuda V5.5。我使用新的项目向导创建了一个CUDA项目,并将cusp路径添加到它的项目属性\VC ++ Directories \Include目录。我在VS2012生成的 *。cu 文件中编写了我的代码,项目已成功编译并构建,但我遇到了 R6010 错误。我通过将项目属性\CUDA C / C ++ \Device\Code生成的默认值从 compute_10,sm_10 更改为 compute_30,sm_30 ,这是我的sm版本。一切运行良好。

I'm using cusp v.0.4.0, cuda V5.5 on VS2012 Ultimate. I created a CUDA project using the new project wizard and added the cusp path to it's project properties\VC++ Directories\Include Directories. I wrote my code in the *.cu file generated by VS2012, the project compiled and built successfully but I got R6010 error on execution. I solved this issue by changing the default value of project properties\CUDA C/C++\Device\Code Generation from compute_10,sm_10 to compute_30,sm_30, which is my sm version. Everything worked well.

现在我想在C ++项目中使用相同的代码。当我将它添加到一个新的C ++项目中,并且我将cusp路径添加到 VC ++ Include Directories 时,项目生成失败,并且在多个文件中出现了大量的语法错误:

Now I want to use the same code in a C++ project. When I added it to a new C++ project and I added the cusp path to VC++ Include Directories, the project build failed with numerous syntax errors in several files:


错误5错误C2144:语法错误:'void'应该在';'前面c:\users\administrator\downloads\android\cusplibrary-master\ cusplibrary-master\cusp\detail\device\spmv\coo_flat.h 164

Error 5 error C2144: syntax error : 'void' should be preceded by ';' c:\users\administrator\downloads\android\cusplibrary-master\cusplibrary-master\cusp\detail\device\spmv\coo_flat.h 164

22 IntelliSense:expect a';'c:\Users\\ \\管理员\Downloads\Android\cusplibrary-master\cusplibrary-master\cusp\detail\device\spmv\coo_flat.h 272

22 IntelliSense: expected a ';' c:\Users\Administrator\Downloads\Android\cusplibrary-master\cusplibrary-master\cusp\detail\device\spmv\coo_flat.h 272

...

还有其他108个错误。如果这些是语法错误,为什么没有任何显示在我的CUDA解决方案?如何成功地在C ++项目中构建我的代码?

There are 108 more errors like these. If these are syntax errors, why didn't any of them show up in my CUDA solution? How can I successfully build my code in a C++ project?

#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <cusp/krylov/cg.h>
#include <cusp/csr_matrix.h>
#include <cusp/hyb_matrix.h>
#include <cusp/gallery/poisson.h>
#include <cusp/io/matrix_market.h>
#include <cusp\print.h>
#include <fstream>
#include <conio.h>
#include <math.h>
#include <iostream>

#include <windows.h>

using namespace std;
int main() 
{
    int N = 10000;
    int nnz = 1005070;
    DWORD dw1 = GetTickCount();
    cusp::csr_matrix<int,double,cusp::device_memory> A(N,N,nnz);
    DWORD dw2 = GetTickCount();
    double dw3 = dw2 - dw1;
    cout << "alocating A matrix time : " << dw3 << endl;

    ifstream rowOffseFile;
    ifstream colIndexFile;
    ifstream valuesFile;
    ifstream ansFile;

    rowOffseFile.open("C:\\Users\\Administrator\\Documents\\MATLAB\\10000_0.01_RO.txt");
    int *rowOffset = NULL;
    rowOffset = (int *)malloc((N+1)*sizeof(int));
    for (int i = 0; i < N+1; i++)
    {
        rowOffset[i] = 0;
    }
    int i =0;
    if (rowOffseFile.is_open()) {
        while (!rowOffseFile.eof()) {
            rowOffseFile >> rowOffset[i];
            i+=1;
        }
    }
    rowOffseFile.close();
    DWORD dw10 = GetTickCount();
    for (int i = 0; i < (N+1); i++)
    {
        A.row_offsets[i] = rowOffset[i];
    }
    DWORD dw11 = GetTickCount();
    double dw12 =dw11 - dw10;

    ///////////////////////////////////////////////////////////////////////////////////
    colIndexFile.open("C:\\Users\\Administrator\\Documents\\MATLAB\\10000_0.01_CI.txt");
    int *colIndex = NULL;
    colIndex = (int *)malloc((nnz)*sizeof(int));
    for (int i = 0; i < nnz; i++)
    {
        colIndex[i] = 0;
    }
    i =0;
    if (colIndexFile.is_open()) {
        while (!colIndexFile.eof()) {
            colIndexFile >> colIndex[i];
            //int temp = (int)output;
            //cout<< colIndex[i] << endl;
            i+=1;
        }
    }
    colIndexFile.close();
    DWORD ex1 = GetTickCount();
    for (int i = 0; i < nnz; i++)
    {
        A.column_indices[i] = colIndex[i];
    }
    DWORD ex2 = GetTickCount();
    double t = ex2-ex1;

    /////////////////////////////////////////////////////////////
    valuesFile.open("C:\\Users\\Administrator\\Documents\\MATLAB\\10000_0.01_V.txt");
    double *values = NULL;
    values = (double *)malloc((nnz)*sizeof(double));
    for (int i = 0; i < nnz; i++)
    {
        values[i] = 0;
    }
    i =0;
    if (valuesFile.is_open()) {
        while (!valuesFile.eof()) {
            valuesFile >> values[i];
            //int temp = (int)output;
            //cout<< colIndex[i] << endl;
            i+=1;
        }
    }
    valuesFile.close();
    DWORD ex3 = GetTickCount();
    for (int i = 0; i < nnz; i++)
    {
        A.values[i] = values[i];
    }
    DWORD ex4 = GetTickCount();
    t = t+ex4-ex3+dw12;
    cout << "time spent on initializing: " << t <<endl;

    DWORD dw7 = GetTickCount();
    cusp::array1d<double,cusp::device_memory> X(N,0.);
    cusp::array1d<double,cusp::device_memory> B(N,1.);
    DWORD dw8 = GetTickCount();
    double dw9 = dw8-dw7;
    cout << "time spent on allocating X and B :" << dw9 << endl;
    DWORD dw4 = GetTickCount();

    cusp::krylov::cg(A,X,B);
    DWORD dw5 = GetTickCount();
    double dw6 = dw5 - dw4;
    std::cout << "time spenton solving : " << dw6 << std::endl;
    //cusp::print(X);

    ansFile.open("C:\\Users\\Administrator\\Documents\\MATLAB\\10000_0.01_X.txt");
    double *ans = NULL;
    ans = (double *)malloc((N)*sizeof(double));
    for (int i = 0; i < N; i++)
    {
        ans[i] = 0;
    }

    i =0;
    if (ansFile.is_open()) {
        while (!ansFile.eof()) {
            ansFile >> ans[i];
            //int temp = (int)output;
            //cout<< rowOffset[i] << endl;
            i+=1;
        }
    }
    ansFile.close();

    double tol = 0;
    double temp = 0;
    for (int i = 0; i < N; i++)
    {
        temp = abs(X[i] - ans[i]);
        if (temp>tol)
        {
            tol = temp;
        }
    }
    cout << "max tol is :" << tol << endl;

    getch();

    return 0;
}


推荐答案


现在我想在C ++中的一个书面项目中使用这段代码,但是当我将一个相同的代码添加到一个新的C ++项目...

"Now I want to use this piece of code in a written Project in C++, but when I added that very same code to a new C++ project ... "

这可能不会工作。如果这个代码在C ++项目中的.cpp文件中,它将不起作用。

That probably won't work. If this code is in a .cpp in a C++ project, it won't work.

cusp是一个基于推力构建的模板库CUDA顶部,因此必须通过 nvcc 编译cusp代码 ,即它必须位于VS中的CUDA项目中,而不是普通的C ++项目。

cusp is a template library that is built on top of thrust which is built on top of CUDA, so cusp codes must be compiled by nvcc, i.e. it must be in a CUDA project in VS, not an ordinary C++ project.

因此,请回到在VS中使用CUDA项目的尖点代码。

So go back to using a CUDA project in VS for your cusp codes.

这篇关于在Visual Studio C ++项目中使用尖峰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆