2015-04-02 86 views
0
__global__ void HYPER (int tFast, int tFastLenth, int kilo, int lenPrzvFast, double eps, int AF,double *arrINTLighFast, int *arrPrzvFncFst, int dv_ptr) 
    { 
    for(int j = 0;j<(tFast*tFastLenth);j++) 
     { arrINTLighFast[j]=0; 
     } 
      for(int j = 0;j<(kilo);j++) arrPrzvFncFst[j]=0; 
    for(int j = 1;j<(tFast*tFastLenth);j++) 
     { arrINTLighFast[j]= arrINTLighFast[j-1] + AF*exp(-j/(eps+tFast)); } 

    for(int j = 0;j<(tFast*tFastLenth-1);j++) 
     { 
      for(int i=(arrINTLighFast[j]);i< (arrINTLighFast[j+1]);i++) 
       {arrPrzvFncFst[i]=j;} 
     } 
    for(int j = 0;j<lenPrzvFast;j++) 
     { devvecPrzvFncFst61440Slow149998[j]= arrPrzvFncFst[j] ;} 
} 


int main (void) 
{ 
const int tFast = 9; 
const int tFastLenth = 6; 
double arrINTLighFast[tFast*tFastLenth]; 
int arrPrzvFncFst[61500]; 
int AF = 1000; 
int kilo = 1024; 
int kilo150 = 149998; 
const double eps=0.0000001; 
const int lenPrzvFast=61500; 

    thrust::host_vector<int> vecPrzvFncFst61440Slow149998; 
    int Len_vecPrzv=(lenPrzvFast+kilo150);  
    for (int j=0;j<Len_vecPrzv;j++) vecPrzvFncFst61440Slow149998.push_back(0); 
    for (int j=0;j<Len_vecPrzv;j++)  vecPrzvFncFst61440Slow149998 [j] = 0; 
    thrust::device_vector<int> devvecPrzvFncFst61440Slow149998 = vecPrzvFncFst61440Slow149998; 

    int *dv_ptr = thrust::raw_pointer_cast(devvecPrzvFncFst61440Slow149998.data()); 

    HYPER <<<blocks, threads>>>(tFast, tFastLenth, kilo, lenPrzvFast, eps, AF, arrINTLighFast, arrPrzvFncFst, dv_ptr); 

    thrust::host_vector<int> HostvecPrzvFncFst61440Slow149998 = devvecPrzvFncFst61440Slow149998; 
    std::cout << "Device vector is: " << std::endl; 
    for(int j = 0; j<vecPrzvFncFst61440Slow149998.size(); j++) 
      std::cout << "vecPrzvFncFst61440Slow149998[" << j << "] = " << HostvecPrzvFncFst61440Slow149998[j] << std::endl; 
return 0; 
} 

還有就是我不能在函數中使用向量問題發揮作用,所以我決定用推力:: raw_pointer_cast。然而,我有問題:在編譯期間,我有一個錯誤:標識符「devvecPrzvFncFst61440Slow149998」未定義。第二個是我不能明確地找出如何將int * dv_ptr傳遞給函數和原型,這裏有一個錯誤:類型爲「int *」的參數與類型爲「int」的參數不兼容。我看着在互聯網中,但沒有解決如何順利解決我上面怎麼投推力:: device_vector <int>與原始指針

謝謝您的時間

回答

3

你的內核函數HYPER提到的問題沒有規定的devvecPrzvFncFst61440Slow149998參數,所以當您嘗試使用在這裏:

for(int j = 0;j<lenPrzvFast;j++) 
    { devvecPrzvFncFst61440Slow149998[j]= arrPrzvFncFst[j] ;} 

你會得到未定義的標識符錯誤。這裏沒有什麼魔力,你的CUDA內核大部分都必須遵守普通C函數的規則。如果你想使用一個變量,最好在函數參數中列出(除了全局變量變量和內置變量外,事實並非如此)。

你提到的另一個問題是由於這樣的事實:dv_ptr指針類型:

int *dv_ptr = thrust::raw_pointer_cast(devvecPrzvFncFst61440Slow149998.data()); 

但您正在嘗試將它傳遞的內核參數位置:

​​

即期望普通(非指針)類型:

__global__ void HYPER (..., int dv_ptr) 
          ^^^^^^^^^^ 

下面的代碼有固定的這些問題,完全編譯對我來說:

#include <thrust/host_vector.h> 
#include <thrust/device_vector.h> 

#define blocks 1 
#define threads 1 

__global__ void HYPER (int tFast, int tFastLenth, int kilo, int lenPrzvFast, double eps, int AF,double *arrINTLighFast, int *arrPrzvFncFst, int *dv_ptr) 
    { 
    for(int j = 0;j<(tFast*tFastLenth);j++) 
     { arrINTLighFast[j]=0; 
     } 
      for(int j = 0;j<(kilo);j++) arrPrzvFncFst[j]=0; 
    for(int j = 1;j<(tFast*tFastLenth);j++) 
     { arrINTLighFast[j]= arrINTLighFast[j-1] + AF*exp(-j/(eps+tFast)); } 

    for(int j = 0;j<(tFast*tFastLenth-1);j++) 
     { 
      for(int i=(arrINTLighFast[j]);i< (arrINTLighFast[j+1]);i++) 
       {arrPrzvFncFst[i]=j;} 
     } 
    for(int j = 0;j<lenPrzvFast;j++) 
     { dv_ptr[j]= arrPrzvFncFst[j] ;} 
} 


int main (void) 
{ 
const int tFast = 9; 
const int tFastLenth = 6; 
double arrINTLighFast[tFast*tFastLenth]; 
int arrPrzvFncFst[61500]; 
int AF = 1000; 
int kilo = 1024; 
int kilo150 = 149998; 
const double eps=0.0000001; 
const int lenPrzvFast=61500; 

    thrust::host_vector<int> vecPrzvFncFst61440Slow149998; 
    int Len_vecPrzv=(lenPrzvFast+kilo150); 
    for (int j=0;j<Len_vecPrzv;j++) vecPrzvFncFst61440Slow149998.push_back(0); 
    for (int j=0;j<Len_vecPrzv;j++)  vecPrzvFncFst61440Slow149998 [j] = 0; 
    thrust::device_vector<int> devvecPrzvFncFst61440Slow149998 = vecPrzvFncFst61440Slow149998; 

    int *dv_ptr = thrust::raw_pointer_cast(devvecPrzvFncFst61440Slow149998.data()); 

    HYPER <<<blocks, threads>>>(tFast, tFastLenth, kilo, lenPrzvFast, eps, AF, arrINTLighFast, arrPrzvFncFst, dv_ptr); 

    thrust::host_vector<int> HostvecPrzvFncFst61440Slow149998 = devvecPrzvFncFst61440Slow149998; 
    std::cout << "Device vector is: " << std::endl; 
    for(int j = 0; j<vecPrzvFncFst61440Slow149998.size(); j++) 
      std::cout << "vecPrzvFncFst61440Slow149998[" << j << "] = " << HostvecPrzvFncFst61440Slow149998[j] << std::endl; 
return 0; 
}