 {
   float *temp;
   temp = (float*) malloc(sizeof(float)*N1*N2);
-  checkCudaErrors(cudaMemcpy( temp, dev, sizeof(float) * N1*N2, cudaMemcpyDeviceToHost));
+  cudaMemcpy( temp, dev, sizeof(float) * N1*N2, cudaMemcpyDeviceToHost);
   
   float sum = sum_float_vec(temp, N1*N2);
   free(temp);

#include <cuda_runtime.h>
#include <cuComplex.h>
#include <cublas_v2.h>
#include <helper_functions.h>
#include <helper_cuda.h>

#include <cuda_profiler_api.h>



  // For pascal GPU, the cudaMallocManaged() could probably allow to run larger systems.
  // Need to look for more informations about this!!
  cublasCreate(&handle_cublas_real);
  cublasCreate(&handle_cublas_imag);

  cudaStreamCreate(&stream_mem);
  cudaStreamCreate(&stream_real);
  cudaStreamCreate(&stream_imag);

  cublasSetStream(handle_cublas_real, stream_real);
  cublasSetStream(handle_cublas_imag, stream_imag);

  cudaMalloc( (void **)&ksn2e_d, sizeof(float) * norbs);
  cudaMalloc( (void **)&ksn2f_d, sizeof(float) * norbs);
  cudaMalloc( (void **)&X4_d, sizeof(float) * norbs*norbs);
  
  cudaMalloc( (void **)&sab_d, sizeof(float) * norbs*norbs);

  cudaMalloc( (void **)&nb2v_d, sizeof(float) * nfermi*norbs);
  cudaMalloc( (void **)&nm2v_re_d, sizeof(float) * nfermi*nvirt);
  cudaMalloc( (void **)&nm2v_im_d, sizeof(float) * nfermi*nvirt);

  cudaMemcpy( X4_d, X4, sizeof(float) * norbs*norbs, cudaMemcpyHostToDevice);
  //checkCudaErrors(cublasSetMatrix(norbs, norbs, sizeof(float), X4, norbs, X4_d, norbs));
  cudaMemcpy( ksn2e_d, ksn2e, sizeof(float) * norbs, cudaMemcpyHostToDevice);
  cudaMemcpy( ksn2f_d, ksn2f, sizeof(float) * norbs, cudaMemcpyHostToDevice);

}

extern "C" void free_device()
{

  cudaFree(X4_d);
  cudaFree(ksn2e_d);
  cudaFree(ksn2f_d);

  cudaFree(sab_d);
  cudaFree(nb2v_d);
  cudaFree(nm2v_re_d);
  cudaFree(nm2v_im_d);

  cublasDestroy(handle_cublas_real);
  cublasDestroy(handle_cublas_imag);
  cudaStreamDestroy(stream_mem);
  cudaStreamDestroy(stream_real);
  cudaStreamDestroy(stream_imag);
  cudaProfilerStop();
}

