Created
June 14, 2013 00:30
-
-
Save xianyi/5778561 to your computer and use it in GitHub Desktop.
timming dgemm with int64 interface.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
#include "stdlib.h" | |
#include "sys/time.h" | |
#include "time.h" | |
extern void dgemm_(char*, char*, long*, long*,long*, double*, double*, long*, double*, long*, double*, double*, long*); | |
long main(long argc, char* argv[]) | |
{ | |
long i; | |
printf("test!\n"); | |
if(argc<4){ | |
printf("Input Error\n"); | |
return 1; | |
} | |
long m = atoi(argv[1]); | |
long n = atoi(argv[2]); | |
long k = atoi(argv[3]); | |
long sizeofa = m * k; | |
long sizeofb = k * n; | |
long sizeofc = m * n; | |
char ta = 'N'; | |
char tb = 'N'; | |
double alpha = 1.2; | |
double beta = 0.001; | |
struct timeval start,finish; | |
double duration; | |
double* A = (double*)malloc(sizeof(double) * sizeofa); | |
double* B = (double*)malloc(sizeof(double) * sizeofb); | |
double* C = (double*)malloc(sizeof(double) * sizeofc); | |
srand((unsigned)time(NULL)); | |
for (i=0; i<sizeofa; i++) | |
A[i] = i%3+1;//(rand()%100)/10.0; | |
for (i=0; i<sizeofb; i++) | |
B[i] = i%3+1;//(rand()%100)/10.0; | |
for (i=0; i<sizeofc; i++) | |
C[i] = i%3+1;//(rand()%100)/10.0; | |
//#if 0 | |
printf("m=%d,n=%d,k=%d,alpha=%lf,beta=%lf,sizeofc=%d\n",m,n,k,alpha,beta,sizeofc); | |
gettimeofday(&start, NULL); | |
dgemm_(&ta, &tb, &m, &n, &k, &alpha, A, &m, B, &k, &beta, C, &m); | |
gettimeofday(&finish, NULL); | |
duration = ((double)(finish.tv_sec-start.tv_sec)*1000000 + (double)(finish.tv_usec-start.tv_usec)) / 1000000; | |
double gflops = 2.0 * m *n*k; | |
gflops = gflops/duration*1.0e-6; | |
FILE *fp; | |
fp = fopen("timeDGEMM.txt", "a"); | |
fprintf(fp, "%dx%dx%d\t%lf s\t%lf MFLOPS\n", m, n, k, duration, gflops); | |
fclose(fp); | |
free(A); | |
free(B); | |
free(C); | |
//char* vec[]={"goto", "1000", "1000", "1000"}; | |
//main(4, vec); | |
//#endif | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment