Urmegil

Untitled

Apr 16th, 2017
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <complex>
  3. #include <cublas_v2.h>
  4.  
  5. using namespace std;
  6.  
  7. int main () {
  8.   const double alpha = 1.0;
  9.   const double beta  = 0.0;
  10.   cublasHandle_t handle;
  11.   cublasCreate(&handle);
  12.  
  13.   int xmax = 100;
  14.  
  15.   complex<double>  u[xmax][xmax];
  16.   complex<double>* d_u;
  17.   complex<double>* d_uH;
  18.  
  19.   double arrSize = sizeof(complex<double>) * xmax * xmax;
  20.  
  21.   for(int i = 0;i<xmax;i++) {
  22.     for(int j = 0; j<xmax;j++) {
  23.          u[i][j] = complex<double> (1.0f,1.0f);
  24.     }
  25.   }
  26.   u[49][51] = complex<double> (666.0f,666.0f);
  27.   cudaMalloc(&d_u, arrSize);
  28.   cudaMemcpy(d_u, u, arrSize, cudaMemcpyHostToDevice);
  29.   cudaMalloc(&d_uH, arrSize);
  30.  
  31.   cublasZgeam(handle, CUBLAS_OP_T, CUBLAS_OP_N, xmax, xmax,
  32.                   &alpha, d_u, xmax,
  33.                   &beta,  d_u, xmax,
  34.                   d_uH, xmax);
  35.  
  36.   cudaMemcpy(u, d_uH, arrSize, cudaMemcpyDeviceToHost);
  37.   cout << u[51][49] << endl;
  38.  
  39.   return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment