Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Invoke GPU Kernel in MATLAB for Pointwise Multiplication
Replies: 1   Last Post: Nov 6, 2012 5:37 AM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Jerome Posts: 48 Registered: 12/9/11
Invoke GPU Kernel in MATLAB for Pointwise Multiplication
Posted: Nov 5, 2012 2:35 PM
 Plain Text Reply

I am having difficulty multiplying complex numbers on the GPU.
The values are incorrect from the C=A.*B format.

I am just using one thread to determine if the first element is correct.
My example code is the following:
func.cu
__global__ void matrix_mult(float * A_real, float*A_imag, float*B_real, float *C_real, float *C_imag)
{
int x = blockIdx.x * blockDim.x + threadIdx.x;

C_real =A_real[x]*B_real[x] - A_imag[x] * B_imag[x];
C_imag = A_imag[x]*B_real + A_real[x] * B_imag[x];

}
main_function.m
kernel = parallel.gpu.CUDAKernel('func.ptx',func.cu);
kernel.ThreadBlockSize = [1,1,1]
kernel.GridSize = [1,1]
[x,y]=size(data)
result_real = parallel.gpu.GPUArray.zeros(x,y, 'single');
result_imag = parallel.gpu.GPUArray.zeros(x,y, 'single');
[C_real, C_imag] = feval(kernel, real(A), imag(A), imag(B), real(B), result_real, result_imag)
cvalues=complex(C_real,C_imag);

Thanks in Advance

Date Subject Author
11/5/12 Jerome
11/6/12 Edric Ellis

© The Math Forum at NCTM 1994-2018. All Rights Reserved.