Re: GPU vs CPU in Mathematica 6

• To: mathgroup at smc.vnet.net
• Subject: [mg91142] Re: GPU vs CPU in Mathematica 6
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Thu, 7 Aug 2008 04:40:36 -0400 (EDT)
• References: <g791df\$9i3\$1@smc.vnet.net>

```Hi,

here is a CUDA example that make a 1d Fourier transform
TEMPLATE CODE BEGIN--------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include "cuda.h"
#include "cufft.h"
#include "cutil.h"

typedef float2 Complex;

:Begin:
:Function: cuFourier1d
:Pattern:  cuFourier1d[forwardQ_Integer,data:{__?NumericQ}]
:Arguments: {forwardQ,data}
:ArgumentTypes: {Integer,RealList}
:ReturnType:Manual
:End:

void cuFourier1d(int forwardQ,double *data, long n)
{ cufftHandle plan;
Complex *signal;
cufftComplex *fftData;
long i;
float norm=sqrt((float) n);
int mem_size = sizeof(Complex) * n;

norm=1.0/norm;
signal=(Complex*)malloc(sizeof(Complex) * n);
for(i=0; i<n; i++) {
signal[i].x=(float) data[i];
signal[i].y=0.0f;
}
CUDA_SAFE_CALL(cudaMalloc((void **)&fftData,mem_size));

CUDA_SAFE_CALL(cudaMemcpy( fftData, signal,mem_size ,
cudaMemcpyHostToDevice));

CUFFT_SAFE_CALL(cufftPlan1d(&plan,n,CUFFT_C2C,1));

CUFFT_SAFE_CALL(
cufftExecC2C(plan,fftData,fftData,
forwardQ ? CUFFT_FORWARD : CUFFT_INVERSE));

CUDA_SAFE_CALL(cudaMemcpy(signal, fftData,mem_size ,
cudaMemcpyDeviceToHost));

for(i=0; i<n; i++) {
}

CUFFT_SAFE_CALL(cufftDestroy(plan));
CUDA_SAFE_CALL(cudaFree(fftData));
free(signal);
}

int main(int argc, char *argv[]) {

CUT_DEVICE_INIT(argc, argv);
MLMain(argc,argv);

CUT_EXIT(argc, argv);
}

TEMPLATE CODE END--------------------------------------

preprocess it with mprep to a *.cu file and

You can have a Visual Studio 2005 Project that compile
the stuff.

CUDA don't like the MathLink command line arguments
and gives an error about that, but the rest works  fine.

Regards
Jens

Antonio wrote:
> Dear All,
>
> Is it possible, or has anyone already tried, to use the GPU processing
> instead of the CPU in Mathematica 6?
>
> I ask this question in particular for these new graphic boards (Nvidia
> series 8x)
> http://en.wikipedia.org/wiki/Comparison_of_Nvidia_Graphics_Processing_Units#GeForce_8_series
>
> It should be advantageous to exploit the parallel processing
> capabilities of the GPU. Any hint as to access these Graphics
> functions via Mathematica?
>
> Antonio
>

```

• Prev by Date: Re: Re: Derivative of Dot[]
• Next by Date: Re: Possible bug in Fits.exe on Mac OSX Mathematica 6.0.3
• Previous by thread: Re: GPU vs CPU in Mathematica 6