Commit 0da98aca authored by Swann Perarnau's avatar Swann Perarnau
Browse files

[feature] add regular dgemm with custom alloc

Just to be able to test various matrix placements.
parent 4f575f8c
......@@ -9,5 +9,6 @@ noinst_PROGRAMS = stream_add_pth_st \
stream_add_omp_st \
stream_add_omp_mt \
dgemm_vanilla \
dgemm_mkl \
dgemm_prefetch \
dgemm_noprefetch
#include <aml.h>
#include <assert.h>
#include <errno.h>
#include <mkl.h>
#include <omp.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
AML_ARENA_JEMALLOC_DECL(arena);
AML_AREA_LINUX_DECL(slow);
AML_AREA_LINUX_DECL(fast);
struct bitmask *slowb, *fastb;
struct timespec start, stop;
double *a, *b, *c;
aml_init(&argc, &argv);
assert(argc == 4);
fastb = numa_parse_nodestring_all(argv[1]);
slowb = numa_parse_nodestring_all(argv[2]);
long int N = atol(argv[3]);
unsigned long memsize = sizeof(double)*N*N;
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_area_linux_init(&slow,
AML_AREA_LINUX_MANAGER_TYPE_SINGLE,
AML_AREA_LINUX_MBIND_TYPE_REGULAR,
AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS,
&arena, MPOL_BIND, slowb->maskp));
assert(!aml_area_linux_init(&fast,
AML_AREA_LINUX_MANAGER_TYPE_SINGLE,
AML_AREA_LINUX_MBIND_TYPE_REGULAR,
AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS,
&arena, MPOL_BIND, fastb->maskp));
a = aml_area_malloc(&slow, memsize);
b = aml_area_malloc(&slow, memsize);
c = aml_area_malloc(&fast, memsize);
assert(a != NULL && b != NULL && c != NULL);
double alpha = 1.0, beta = 1.0;
for(unsigned long i = 0; i < N*N; i++){
a[i] = (double)rand();
b[i] = (double)rand();
c[i] = 0.0;
}
clock_gettime(CLOCK_REALTIME, &start);
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, N, N, N, alpha, a, N, b, N, beta, c, N);
clock_gettime(CLOCK_REALTIME, &stop);
long long int time = 0;
time = (stop.tv_nsec - start.tv_nsec) +
1e9* (stop.tv_sec - start.tv_sec);
double flops = (2.0*N*N*N)/(time/1e9);
/* print the flops in GFLOPS */
printf("dgemm-mkl: %llu %lld %lld %f\n", N, memsize, time, flops/1e9);
aml_area_free(&slow, a);
aml_area_free(&slow, b);
aml_area_free(&fast, c);
aml_area_linux_destroy(&slow);
aml_area_linux_destroy(&fast);
aml_finalize();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment