2012-04-05 57 views
0

我想要開始使用C++ Amp函數庫。我正在關注這個MSDN Magazine guide,但是我在這個擴展庫(不是我的代碼)中的代碼部分出現錯誤。Amp函數庫錯誤

protected: 
    _Accelerator_view_impl_ptr _M_accelerator_view; 
    _Accelerator_view_impl_ptr _M_access_on_accelerator_view; 
    void * _M_data_ptr; 
    void * _M_host_ptr; 
    size_t _M_elem_size; 
    size_t _M_num_elems; 
    bool _M_owns_data; 
    bool _M_is_staging; 

誤差

3智能感知:非法參數類型 「無效*」 爲安培限制 功能 「併發::詳細信息:: _ Texture_descriptor :: _ Texture_descriptor(併發::詳細信息: :_Texture * _Texture_ptr)restrict(cpu,amp)「(在」c:\ program files(x86)\ microsoft visual studio 11.0 \ vc \ include \ amprt.h「的538行聲明)c:\ Program Files x86)\ Microsoft Visual Studio 11.0 \ VC \ include \ amprt.h 1466 16

我已經複製到目前爲止

#include <amp.h>    // C++ AMP header file 
#include <iostream>    // For std::cout etc 
using namespace concurrency; // Save some typing :) 
using std::vector;  // Ditto. Comes from <vector> brought in by amp.h 

int main() 
{ 
    do_it(); 

    std::cout << "Hit any key to exit..." << std::endl; 
    std::cin.get(); 
} 

void do_it() 
{ 
    // Rows and columns for matrix 
    const int M = 1024; 
    const int N = 1024; 

    // Create storage for a matrix of above size 
    vector<int> vA(M * N); 
    vector<int> vB(M * N); 

    // Populate matrix objects 
    int i = 0; 
    std::generate(vA.begin(), vA.end(), [&i](){return i++;}); 
    std::generate(vB.begin(), vB.end(), [&i](){return i--;}); 

    // Output storage for matrix calculation 
    vector<int> vC(M * N); 

    perform_calculation(vA, vB, vC, M, N); 
} 

void perform_calculation(
    vector<int>& vA, vector<int>& vB, vector<int>& vC, int M, int N) 
{ 
    for (int i = 0; i < M; i++) 
    { 
     for (int j = 0; j < N; j++) 
     { 
      vC[i * N + j] = vA[i * N + j] + vB[i * N + j]; 
     } 
    } 
} 

構建輸出

------ Build started: Project: Project1, Configuration: Debug Win32------ 
Source.cpp 
LINK : padding exhausted: performing full link 
Project1.vcxproj ->C:\Development\Project1\Debug\Project1.exe 
CodeContracts: 
Project1: Run static contract analysis. 
CodeContracts: Project1: Cannot load assembly 'C:\Development\Project1\Project1\Debub\Decl\Project1.exe' 
CodeContracts: Project1: Total methods analyzed 0 
CodeContracts:Project1: Total time 135ms. 0ms/method 
CodeContracts: Checked 0 assertions. 
CodeContracts: Project1: Static contract analysis done. 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 
+0

這是一個智能感知錯誤 - 當你真正嘗試_build_,你得到了什麼錯誤(如果有的話)? – ildjarn 2012-04-05 18:07:08

+0

@ildjarn我得到一個錯誤,說do_it()沒有定義 – 2012-04-05 18:11:04

+1

這是因爲你在使用它之後聲明'do_it'。移動'main'前面的定義或者在'main'前面添加一個前向聲明 - 這與C++ 11或AMP沒有任何關係,它是非常基本的C++規則。 – ildjarn 2012-04-05 18:12:17

回答

3

智能感知錯誤是衆所周知VS 11測試版的問題無害的代碼。你可以放心地忽略它。在錯誤窗口中,您也可以過濾只顯示打開文件的錯誤,如果您不希望看到它,可以將其過濾掉。但是這並不能阻止你建立和運行,所以忽略。

至於其他與代碼一起發現的問題,請按照MSDN雜誌文章的代碼鏈接,然後您可以使用該代碼,或者使用它來比較您輸入的內容與我提供的內容與文章。

乾杯

丹尼爾