|
@@ -1,6 +1,6 @@
|
|
|
/* StarPU --- Runtime system for heterogeneous multicore architectures.
|
|
|
*
|
|
|
- * Copyright (C) 2009-2012 Université de Bordeaux 1
|
|
|
+ * Copyright (C) 2009-2011 Université de Bordeaux 1
|
|
|
* Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
|
|
|
* Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
|
|
|
*
|
|
@@ -19,13 +19,162 @@
|
|
|
#include <starpu_mpi.h>
|
|
|
#include "mpi_cholesky.h"
|
|
|
#include "mpi_cholesky_models.h"
|
|
|
-#include "mpi_cholesky_codelets.h"
|
|
|
+
|
|
|
+/*
|
|
|
+ * Create the codelets
|
|
|
+ */
|
|
|
+
|
|
|
+static struct starpu_codelet cl11 =
|
|
|
+{
|
|
|
+ .where = STARPU_CPU|STARPU_CUDA,
|
|
|
+ .cpu_funcs = {chol_cpu_codelet_update_u11, NULL},
|
|
|
+#ifdef STARPU_USE_CUDA
|
|
|
+ .cuda_funcs = {chol_cublas_codelet_update_u11, NULL},
|
|
|
+#endif
|
|
|
+ .nbuffers = 1,
|
|
|
+ .modes = {STARPU_RW},
|
|
|
+ .model = &chol_model_11
|
|
|
+};
|
|
|
+
|
|
|
+static struct starpu_codelet cl21 =
|
|
|
+{
|
|
|
+ .where = STARPU_CPU|STARPU_CUDA,
|
|
|
+ .cpu_funcs = {chol_cpu_codelet_update_u21, NULL},
|
|
|
+#ifdef STARPU_USE_CUDA
|
|
|
+ .cuda_funcs = {chol_cublas_codelet_update_u21, NULL},
|
|
|
+#endif
|
|
|
+ .nbuffers = 2,
|
|
|
+ .modes = {STARPU_R, STARPU_RW},
|
|
|
+ .model = &chol_model_21
|
|
|
+};
|
|
|
+
|
|
|
+static struct starpu_codelet cl22 =
|
|
|
+{
|
|
|
+ .where = STARPU_CPU|STARPU_CUDA,
|
|
|
+ .cpu_funcs = {chol_cpu_codelet_update_u22, NULL},
|
|
|
+#ifdef STARPU_USE_CUDA
|
|
|
+ .cuda_funcs = {chol_cublas_codelet_update_u22, NULL},
|
|
|
+#endif
|
|
|
+ .nbuffers = 3,
|
|
|
+ .modes = {STARPU_R, STARPU_R, STARPU_RW},
|
|
|
+ .model = &chol_model_22
|
|
|
+};
|
|
|
|
|
|
/* Returns the MPI node number where data indexes index is */
|
|
|
int my_distrib(int x, int y, int nb_nodes)
|
|
|
{
|
|
|
- //return (x+y) % nb_nodes;
|
|
|
- return (x%dblockx)+(y%dblocky)*dblockx;
|
|
|
+ return (x+y) % nb_nodes;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * code to bootstrap the factorization
|
|
|
+ * and construct the DAG
|
|
|
+ */
|
|
|
+static void dw_cholesky(float ***matA, unsigned size, unsigned ld, unsigned nblocks, int rank, int nodes)
|
|
|
+{
|
|
|
+ struct timeval start;
|
|
|
+ struct timeval end;
|
|
|
+ starpu_data_handle_t **data_handles;
|
|
|
+ int x, y;
|
|
|
+
|
|
|
+ /* create all the DAG nodes */
|
|
|
+ unsigned i,j,k;
|
|
|
+
|
|
|
+ data_handles = malloc(nblocks*sizeof(starpu_data_handle_t *));
|
|
|
+ for(x=0 ; x<nblocks ; x++) data_handles[x] = malloc(nblocks*sizeof(starpu_data_handle_t));
|
|
|
+
|
|
|
+ for(x = 0; x < nblocks ; x++)
|
|
|
+ {
|
|
|
+ for (y = 0; y < nblocks; y++)
|
|
|
+ {
|
|
|
+ int mpi_rank = my_distrib(x, y, nodes);
|
|
|
+ if (mpi_rank == rank)
|
|
|
+ {
|
|
|
+ //fprintf(stderr, "[%d] Owning data[%d][%d]\n", rank, x, y);
|
|
|
+ starpu_matrix_data_register(&data_handles[x][y], 0, (uintptr_t)matA[x][y],
|
|
|
+ ld, size/nblocks, size/nblocks, sizeof(float));
|
|
|
+ }
|
|
|
+ /* TODO: make better test to only registering what is needed */
|
|
|
+ else
|
|
|
+ {
|
|
|
+ /* I don't own that index, but will need it for my computations */
|
|
|
+ //fprintf(stderr, "[%d] Neighbour of data[%d][%d]\n", rank, x, y);
|
|
|
+ starpu_matrix_data_register(&data_handles[x][y], -1, (uintptr_t)NULL,
|
|
|
+ ld, size/nblocks, size/nblocks, sizeof(float));
|
|
|
+ }
|
|
|
+ if (data_handles[x][y])
|
|
|
+ {
|
|
|
+ starpu_data_set_rank(data_handles[x][y], mpi_rank);
|
|
|
+ starpu_data_set_tag(data_handles[x][y], (y*nblocks)+x);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ starpu_mpi_barrier(MPI_COMM_WORLD);
|
|
|
+ gettimeofday(&start, NULL);
|
|
|
+
|
|
|
+ for (k = 0; k < nblocks; k++)
|
|
|
+ {
|
|
|
+ int prio = STARPU_DEFAULT_PRIO;
|
|
|
+ if (!noprio) prio = STARPU_MAX_PRIO;
|
|
|
+
|
|
|
+ starpu_mpi_insert_task(MPI_COMM_WORLD, &cl11,
|
|
|
+ STARPU_PRIORITY, prio,
|
|
|
+ STARPU_RW, data_handles[k][k],
|
|
|
+ 0);
|
|
|
+
|
|
|
+ for (j = k+1; j<nblocks; j++)
|
|
|
+ {
|
|
|
+ prio = STARPU_DEFAULT_PRIO;
|
|
|
+ if (!noprio&& (j == k+1)) prio = STARPU_MAX_PRIO;
|
|
|
+ starpu_mpi_insert_task(MPI_COMM_WORLD, &cl21,
|
|
|
+ STARPU_PRIORITY, prio,
|
|
|
+ STARPU_R, data_handles[k][k],
|
|
|
+ STARPU_RW, data_handles[k][j],
|
|
|
+ 0);
|
|
|
+
|
|
|
+ for (i = k+1; i<nblocks; i++)
|
|
|
+ {
|
|
|
+ if (i <= j)
|
|
|
+ {
|
|
|
+ prio = STARPU_DEFAULT_PRIO;
|
|
|
+ if (!noprio && (i == k + 1) && (j == k +1) ) prio = STARPU_MAX_PRIO;
|
|
|
+ starpu_mpi_insert_task(MPI_COMM_WORLD, &cl22,
|
|
|
+ STARPU_PRIORITY, prio,
|
|
|
+ STARPU_R, data_handles[k][i],
|
|
|
+ STARPU_R, data_handles[k][j],
|
|
|
+ STARPU_RW, data_handles[i][j],
|
|
|
+ 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ starpu_task_wait_for_all();
|
|
|
+
|
|
|
+ for(x = 0; x < nblocks ; x++)
|
|
|
+ {
|
|
|
+ for (y = 0; y < nblocks; y++)
|
|
|
+ {
|
|
|
+ if (data_handles[x][y])
|
|
|
+ starpu_data_unregister(data_handles[x][y]);
|
|
|
+ }
|
|
|
+ free(data_handles[x]);
|
|
|
+ }
|
|
|
+ free(data_handles);
|
|
|
+
|
|
|
+ starpu_mpi_barrier(MPI_COMM_WORLD);
|
|
|
+ gettimeofday(&end, NULL);
|
|
|
+
|
|
|
+ if (rank == 0)
|
|
|
+ {
|
|
|
+ double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
|
|
|
+ fprintf(stderr, "Computation took (in ms)\n");
|
|
|
+ fprintf(stdout, "%2.2f\n", timing/1000);
|
|
|
+
|
|
|
+ double flop = (1.0f*size*size*size)/3.0f;
|
|
|
+ fprintf(stderr, "Synthetic GFlops : %2.2f\n", (flop/timing/1000.0f));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
@@ -36,45 +185,35 @@ int main(int argc, char **argv)
|
|
|
* */
|
|
|
|
|
|
float ***bmat;
|
|
|
- int rank, nodes, ret;
|
|
|
+ int rank, nodes;
|
|
|
|
|
|
parse_args(argc, argv);
|
|
|
|
|
|
- ret = starpu_init(NULL);
|
|
|
+ struct starpu_conf conf;
|
|
|
+ starpu_conf_init(&conf);
|
|
|
+
|
|
|
+ conf.sched_policy_name = "heft";
|
|
|
+ conf.calibrate = 1;
|
|
|
+
|
|
|
+ int ret = starpu_init(&conf);
|
|
|
STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
|
|
|
|
|
|
starpu_mpi_initialize_extended(&rank, &nodes);
|
|
|
starpu_helper_cublas_init();
|
|
|
|
|
|
- if (dblockx == -1 || dblocky == -1)
|
|
|
- {
|
|
|
- int factor;
|
|
|
- dblockx = nodes;
|
|
|
- dblocky = 1;
|
|
|
- for(factor=sqrt(nodes) ; factor>1 ; factor--)
|
|
|
- {
|
|
|
- if (nodes % factor == 0)
|
|
|
- {
|
|
|
- dblockx = nodes/factor;
|
|
|
- dblocky = factor;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
unsigned i,j,x,y;
|
|
|
- bmat = malloc(nblocks * sizeof(float *));
|
|
|
- for(x=0 ; x<nblocks ; x++)
|
|
|
+ bmat = malloc(nblocks * sizeof(float *));
|
|
|
+ for(x=0 ; x<nblocks ; x++)
|
|
|
{
|
|
|
- bmat[x] = malloc(nblocks * sizeof(float *));
|
|
|
- for(y=0 ; y<nblocks ; y++)
|
|
|
+ bmat[x] = malloc(nblocks * sizeof(float *));
|
|
|
+ for(y=0 ; y<nblocks ; y++)
|
|
|
{
|
|
|
- starpu_malloc((void **)&bmat[x][y], BLOCKSIZE*BLOCKSIZE*sizeof(float));
|
|
|
+ starpu_malloc((void **)&bmat[x][y], BLOCKSIZE*BLOCKSIZE*sizeof(float));
|
|
|
for (i = 0; i < BLOCKSIZE; i++)
|
|
|
{
|
|
|
for (j = 0; j < BLOCKSIZE; j++)
|
|
|
{
|
|
|
- bmat[x][y][j +i*BLOCKSIZE] = (1.0f/(1.0f+(i+(x*BLOCKSIZE)+j+(y*BLOCKSIZE)))) + ((i+(x*BLOCKSIZE) == j+(y*BLOCKSIZE))?1.0f*size:0.0f);
|
|
|
+ bmat[x][y][j +i*BLOCKSIZE] = (1.0f/(1.0f+(i+(x*BLOCKSIZE)+j+(y*BLOCKSIZE)))) + ((i+(x*BLOCKSIZE) == j+(y*BLOCKSIZE))?1.0f*size:0.0f);
|
|
|
//mat[j +i*size] = ((i == j)?1.0f*size:0.0f);
|
|
|
}
|
|
|
}
|
|
@@ -82,15 +221,15 @@ int main(int argc, char **argv)
|
|
|
}
|
|
|
|
|
|
|
|
|
- if (display)
|
|
|
+ if (display)
|
|
|
{
|
|
|
- printf("[%d] Input :\n", rank);
|
|
|
+ printf("[%d] Input :\n", rank);
|
|
|
|
|
|
for(y=0 ; y<nblocks ; y++)
|
|
|
{
|
|
|
for(x=0 ; x<nblocks ; x++)
|
|
|
{
|
|
|
- printf("Block %u,%u :\n", x, y);
|
|
|
+ printf("Block %d,%d :\n", x, y);
|
|
|
for (j = 0; j < BLOCKSIZE; j++)
|
|
|
{
|
|
|
for (i = 0; i < BLOCKSIZE; i++)
|
|
@@ -110,19 +249,18 @@ int main(int argc, char **argv)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- double timing, flops;
|
|
|
- dw_cholesky(bmat, size, size/nblocks, nblocks, rank, nodes, &timing, &flops);
|
|
|
+ dw_cholesky(bmat, size, size/nblocks, nblocks, rank, nodes);
|
|
|
|
|
|
starpu_mpi_shutdown();
|
|
|
|
|
|
- if (display)
|
|
|
+ if (display)
|
|
|
{
|
|
|
- printf("[%d] Results :\n", rank);
|
|
|
+ printf("[%d] Results :\n", rank);
|
|
|
for(y=0 ; y<nblocks ; y++)
|
|
|
{
|
|
|
for(x=0 ; x<nblocks ; x++)
|
|
|
{
|
|
|
- printf("Block %u,%u :\n", x, y);
|
|
|
+ printf("Block %d,%d :\n", x, y);
|
|
|
for (j = 0; j < BLOCKSIZE; j++)
|
|
|
{
|
|
|
for (i = 0; i < BLOCKSIZE; i++)
|
|
@@ -143,19 +281,19 @@ int main(int argc, char **argv)
|
|
|
}
|
|
|
|
|
|
float *rmat = malloc(size*size*sizeof(float));
|
|
|
- for(x=0 ; x<nblocks ; x++)
|
|
|
+ for(x=0 ; x<nblocks ; x++)
|
|
|
{
|
|
|
- for(y=0 ; y<nblocks ; y++)
|
|
|
+ for(y=0 ; y<nblocks ; y++)
|
|
|
{
|
|
|
- for (i = 0; i < BLOCKSIZE; i++)
|
|
|
+ for (i = 0; i < BLOCKSIZE; i++)
|
|
|
{
|
|
|
- for (j = 0; j < BLOCKSIZE; j++)
|
|
|
+ for (j = 0; j < BLOCKSIZE; j++)
|
|
|
{
|
|
|
- rmat[j+(y*BLOCKSIZE)+(i+(x*BLOCKSIZE))*size] = bmat[x][y][j +i*BLOCKSIZE];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ rmat[j+(y*BLOCKSIZE)+(i+(x*BLOCKSIZE))*size] = bmat[x][y][j +i*BLOCKSIZE];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
fprintf(stderr, "[%d] compute explicit LLt ...\n", rank);
|
|
|
for (j = 0; j < size; j++)
|
|
@@ -172,63 +310,62 @@ int main(int argc, char **argv)
|
|
|
STARPU_ASSERT(test_mat);
|
|
|
|
|
|
SSYRK("L", "N", size, size, 1.0f,
|
|
|
- rmat, size, 0.0f, test_mat, size);
|
|
|
+ rmat, size, 0.0f, test_mat, size);
|
|
|
|
|
|
fprintf(stderr, "[%d] comparing results ...\n", rank);
|
|
|
- if (display)
|
|
|
+ if (display)
|
|
|
{
|
|
|
- for (j = 0; j < size; j++)
|
|
|
+ for (j = 0; j < size; j++)
|
|
|
{
|
|
|
- for (i = 0; i < size; i++)
|
|
|
+ for (i = 0; i < size; i++)
|
|
|
{
|
|
|
- if (i <= j)
|
|
|
+ if (i <= j)
|
|
|
{
|
|
|
- printf("%2.2f\t", test_mat[j +i*size]);
|
|
|
- }
|
|
|
- else
|
|
|
+ printf("%2.2f\t", test_mat[j +i*size]);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- printf(".\t");
|
|
|
- }
|
|
|
- }
|
|
|
- printf("\n");
|
|
|
- }
|
|
|
- }
|
|
|
+ printf(".\t");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
int correctness = 1;
|
|
|
- for(x = 0; x < nblocks ; x++)
|
|
|
+ for(x = 0; x < nblocks ; x++)
|
|
|
{
|
|
|
- for (y = 0; y < nblocks; y++)
|
|
|
+ for (y = 0; y < nblocks; y++)
|
|
|
{
|
|
|
- int mpi_rank = my_distrib(x, y, nodes);
|
|
|
- if (mpi_rank == rank)
|
|
|
+ int mpi_rank = my_distrib(x, y, nodes);
|
|
|
+ if (mpi_rank == rank)
|
|
|
{
|
|
|
- for (i = (size/nblocks)*x ; i < (size/nblocks)*x+(size/nblocks); i++)
|
|
|
- {
|
|
|
- for (j = (size/nblocks)*y ; j < (size/nblocks)*y+(size/nblocks); j++)
|
|
|
- {
|
|
|
- if (i <= j)
|
|
|
- {
|
|
|
- float orig = (1.0f/(1.0f+i+j)) + ((i == j)?1.0f*size:0.0f);
|
|
|
- float err = abs(test_mat[j +i*size] - orig);
|
|
|
- if (err > 0.00001)
|
|
|
+ for (i = (size/nblocks)*x ; i < (size/nblocks)*x+(size/nblocks); i++)
|
|
|
+ {
|
|
|
+ for (j = (size/nblocks)*y ; j < (size/nblocks)*y+(size/nblocks); j++)
|
|
|
+ {
|
|
|
+ if (i <= j)
|
|
|
+ {
|
|
|
+ float orig = (1.0f/(1.0f+i+j)) + ((i == j)?1.0f*size:0.0f);
|
|
|
+ float err = abs(test_mat[j +i*size] - orig);
|
|
|
+ if (err > 0.00001)
|
|
|
{
|
|
|
- fprintf(stderr, "[%d] Error[%u, %u] --> %2.2f != %2.2f (err %2.2f)\n", rank, i, j, test_mat[j +i*size], orig, err);
|
|
|
+ fprintf(stderr, "[%d] Error[%d, %d] --> %2.2f != %2.2f (err %2.2f)\n", rank, i, j, test_mat[j +i*size], orig, err);
|
|
|
correctness = 0;
|
|
|
- flops = 0;
|
|
|
break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- for(x=0 ; x<nblocks ; x++)
|
|
|
+ for(x=0 ; x<nblocks ; x++)
|
|
|
{
|
|
|
- for(y=0 ; y<nblocks ; y++)
|
|
|
+ for(y=0 ; y<nblocks ; y++)
|
|
|
{
|
|
|
- starpu_free((void *)bmat[x][y]);
|
|
|
+ starpu_free((void *)bmat[x][y]);
|
|
|
}
|
|
|
free(bmat[x]);
|
|
|
}
|
|
@@ -236,16 +373,9 @@ int main(int argc, char **argv)
|
|
|
free(rmat);
|
|
|
free(test_mat);
|
|
|
|
|
|
- starpu_helper_cublas_shutdown();
|
|
|
+ starpu_helper_cublas_shutdown();
|
|
|
starpu_shutdown();
|
|
|
|
|
|
assert(correctness);
|
|
|
-
|
|
|
- if (rank == 0)
|
|
|
- {
|
|
|
- fprintf(stdout, "Computation time (in ms): %2.2f\n", timing/1000);
|
|
|
- fprintf(stdout, "Synthetic GFlops : %2.2f\n", (flops/timing/1000.0f));
|
|
|
- }
|
|
|
-
|
|
|
return 0;
|
|
|
}
|