Hi!
I'm new to MAGMA.
My code uses that LAPACK function zgeev for solving a Eigenvalue problem. I'm trying to use the MAGMA implementation of zgeev in my code. In my code, I use std::complex<double> to store complex numbers and MAGMA uses cuDoubleComplex. So is there any way to convert from std::complex<double> to cuDoubleComplex without having to allocate more memory?
Thanks!
Harshad
std::complex<double> to cuComplexDouble
Re: std::complex<double> to cuComplexDouble
They are binary compatible. Just use a cast. For instance:
Code: Select all
// This does some simple tests to verify that C++ complex<float>
// and CUDA's cuFloatComplex are compatible, as one would expect.
#include <stdio.h>
#include <complex>
#include <cublas_v2.h>
int main( int argc, char** argv )
{
std::complex<float> *hx, *dx, *dy;
std::complex<float> alpha = 2.0;
float sum;
int n = 100;
cublasHandle_t handle;
cublasCreate( &handle );
// create vectors
hx = new std::complex<float>[ n ];
cudaMalloc( &dx, n*sizeof(std::complex<float>) );
cudaMalloc( &dy, n*sizeof(std::complex<float>) );
for( int i=0; i < n; ++i ) {
hx[i] = i;
}
cublasSetVector( n, sizeof(std::complex<float>), hx, 1, dx, 1 );
cublasSetVector( n, sizeof(std::complex<float>), hx, 1, dy, 1 );
// y += alpha*x
// sum( y )
// ----- with cublas v1:
// cublasCaxpy( n, *((cuFloatComplex*) &alpha), (cuFloatComplex*) dx, 1, (cuFloatComplex*) dy, 1 );
// sum = cublasScasum( n, (cuFloatComplex*) dy, 1 );
// ----- with cublas v2:
cublasCaxpy( handle, n, (cuFloatComplex*) &alpha, (cuFloatComplex*) dx, 1, (cuFloatComplex*) dy, 1 );
cublasScasum( handle, n, (cuFloatComplex*) dy, 1, &sum );
printf( "sum %.2f\n", sum );
// cleanup
cudaFree( dx );
cudaFree( dy );
delete[] hx;
cublasDestroy( handle );
return 0;
}
Re: std::complex<double> to cuComplexDouble
Thanks, this works!