#include #include #include #include #include #define CUDA_CHK(NAME, ARGS) { \ cudaError_t cuda_err_code = NAME ARGS; \ if (cuda_err_code != cudaSuccess) { \ printf("%s failed with code %d\n", #NAME, cuda_err_code); \ abort(); \ } \ } #ifndef max #define max( a, b ) ( ((a) > (b)) ? (a) : (b) ) #endif #ifndef min #define min( a, b ) ( ((a) < (b)) ? (a) : (b) ) #endif #define MAT1 3 #define MAT2 MAT1*MAT1 #define TINY 1.0e-40 #define a(i,j) a[(i)*MAT1+(j)] #define GO 1 #define NOGO 0 void Check_Kernel(const char *message){ cudaError_t error = cudaGetLastError(); if (error != cudaSuccess){ fprintf(stderr,"Error: %s:%s\n",message, cudaGetErrorString(error)); } } __device__ void d_pivot_decomp(float *a, int *p, int *q){ int i,j,k; int n=MAT1; int pi,pj,tmp; float max; float ftmp; for (k=0;kmax){ max = fabs(a(i,j)); pi=i; pj=j; } } } //Swap Row tmp=p[k]; p[k]=p[pi]; p[pi]=tmp; for (j=0;jTINY)){ for (i=k+1;i=0;i--){ ftmp=xtmp[i]; for (j=i+1;j>>(d_A,d_b,matrixcount); cudaDeviceSynchronize(); Check_Kernel("Solve"); printf("Ran solve\n"); CUDA_CHK(cudaEventRecord, (evt_stop, 0)); CUDA_CHK(cudaEventSynchronize, (evt_stop)); float total_time; CUDA_CHK(cudaEventElapsedTime, (&total_time, evt_start, evt_stop)); CUDA_CHK(cudaMemcpy, (h_A,d_A, sizeof(float)*matsize, cudaMemcpyDeviceToHost)); CUDA_CHK(cudaMemcpy, (h_x,d_b, sizeof(float)*vecsize, cudaMemcpyDeviceToHost)); // print timing results float one_time = total_time * 1e-3; printf("time: %g s\n", one_time); for (unsigned int i=0; i