GUI for CUDA program

i’m using visual studio 2008 and want to create a GUI for a code that computes matrix multiplication on the host and on the device.

it takes the dimension of the square matrix from the user, when a button is clicked, it calculates the time taken by both CPU and GPU and displays it. i have written the code but am not sure how to design the GUI. here is my code:

[codebox]//MULTIPLICATION OF A 2D MATRIX CUDA PROGRAM

//GLOBAL VARIABLES

int s=512;

int BLOCK_SIZE= 16;

int WIDTH = s;

int HEIGHT = s;

//HEADER FILES

#include <stdio.h>

#include <stdlib.h>

#include <cuda_runtime.h>

#include <cutil.h>

#include <conio.h>

struct Matrix {

int width;

int height;

int* dat ;

};

// ALLOCATION OF DATA TO MATRIX

void Init(int* data, unsigned int size)

{

for (int i = 0; i < size; ++i)

    data[i] = 1;

}

//KERNEL TO RUN ON GPU CALLED by MatMul()

global void MatMulKernel(Matrix A, Matrix B, Matrix C)

{

int sum = 0;

int r = blockIdx.x * blockDim.x + threadIdx.y;

int c = blockIdx.y * blockDim.y + threadIdx.x;

	for (int e = 0; e < A.width; ++e)

	sum += A.dat[r * A.width + e]* B.dat[e * B.width + c];

C.dat[r * C.width + c] = sum;

}

// MATRIX MULTIPLICATION FUNCTION CALLIN GPU KERNEL

void MatMul(const Matrix A, const Matrix B, Matrix C)

{

Matrix d_A,d_B,d_C;

size_t size = A.width * A.height * sizeof(unsigned int);

d_A.width =A.width; d_A.height = A.width;

cudaMalloc((void**)&d_A.dat, size);

cudaMemcpy(d_A.dat,A.dat, size,cudaMemcpyHostToDevice);

d_B.width = B.width; d_B.height = B.height;

cudaMalloc((void**)&d_B.dat, size);

cudaMemcpy(d_B.dat, B.dat, size,cudaMemcpyHostToDevice);

d_C.width = C.width; d_C.height = C.height;

size = C.width * C.height * sizeof(int);

cudaMalloc((void**)&d_C.dat, size);

dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE);

dim3 dimGrid(B.width / dimBlock.x, A.height / dimBlock.y);

unsigned int timer = 0;

cutCreateTimer( &timer);

cutStartTimer( timer);

MatMulKernel<<<dimGrid, dimBlock>>>(d_A, d_B, d_C);

cudaThreadSynchronize();

// Display Timer

cutStopTimer( timer);

printf(“Processing time GPU: %f (ms)\n”, cutGetTimerValue( timer));

cutDeleteTimer( timer);

cudaMemcpy(C.dat, d_C.dat, size,cudaMemcpyDeviceToHost);

cudaFree(d_A.dat);

cudaFree(d_B.dat);

cudaFree(d_C.dat);

}

//MAIN

int main()

{

printf("\nEnter dimension of square matrix :");

scanf("%d",&s);

Matrix h_A,h_B,h_C;

h_A.width=WIDTH;

h_A.height=HEIGHT;

h_B.width=WIDTH;

h_B.height=HEIGHT;

h_C.width=WIDTH;

h_C.height=HEIGHT;

unsigned int size = WIDTH*HEIGHT;

unsigned int mem_size = sizeof(int) * size;

h_A.dat= (int*) malloc(mem_size);

h_B.dat= (int*) malloc(mem_size);

h_C.dat= (int*) malloc(mem_size);

Init(h_A.dat, size);

Init(h_B.dat, size);

//invoke MatMul

MatMul(h_A,h_B,h_C);

int **a,**b,**c;

unsigned int r1,r2,r3,c1,c2,c3;

int i,j,k;

r1=r2=r3=c1=c2=c3=s;

a = (int **) malloc(c1 * sizeof(int *));

for(i = 0; i < c1; i++)

{

a[i] = (int *) malloc(r1 * sizeof(int));

}

b = (int **) malloc(c1 * sizeof(int *));

for(i = 0; i < c1; i++)

{

b[i] = (int *) malloc(r1 * sizeof(int));

}

c = (int **) malloc(c1 * sizeof(int *));

for(i = 0; i < c1; i++)

{

c[i] = (int *) malloc(r1 * sizeof(int));

}

for (i=0;i<r1;i++)

{	

	for(j=0;j<c1;j++)

	{

	a[i][j]=1;

	b[i][j]=1;

	}

}

unsigned int timer2 = 0;

cutCreateTimer( &timer2);

cutStartTimer( timer2);

if(c1!=r2)

	printf("\nMultipliation not possible");

else

{

	for(i=0;i<r1;i++)

		for(j=0;j<c2;j++)

			for(k=0;k<c1;k++)

				c[i][j]+=a[i][k]*b[k][j];

}

cutStopTimer( timer2);

printf("Processing time CPU: %f (ms)\n", cutGetTimerValue( timer2));

cutDeleteTimer( timer2);

for(i = 0; i < c1; i++)

free(a[i]);

free(a);

for(i = 0; i < c1; i++)

free(b[i]);

free(B);

for(i = 0; i < c1; i++)

free(c[i]);

free©;

getche();

return 0;

}[/codebox]

anybody knows how i can design a GUI??i am pretty new to visual studio and i read somewhere that creating a GUI in C++ is quite difficult…

This isn’t a CUDA question… you’d have better luck asking this in another forum.

I have very little experience with GUI’s but I believe looking into ‘OpenGL’ might be a good start?