/* StarPU --- Runtime system for heterogeneous multicore architectures. * * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria * * StarPU is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or (at * your option) any later version. * * StarPU is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Lesser General Public License in COPYING.LGPL for more details. */ #include "mpi_cholesky.h" #include #include #include #include /* * Create the codelets */ static struct starpu_codelet cl11 = { .cpu_funcs = {chol_cpu_codelet_update_u11}, #ifdef STARPU_USE_CUDA .cuda_funcs = {chol_cublas_codelet_update_u11}, #elif defined(STARPU_SIMGRID) .cuda_funcs = {(void*)1}, #endif .nbuffers = 1, .modes = {STARPU_RW}, .model = &chol_model_11, .color = 0xffff00, }; static struct starpu_codelet cl21 = { .cpu_funcs = {chol_cpu_codelet_update_u21}, #ifdef STARPU_USE_CUDA .cuda_funcs = {chol_cublas_codelet_update_u21}, #elif defined(STARPU_SIMGRID) .cuda_funcs = {(void*)1}, #endif .cuda_flags = {STARPU_CUDA_ASYNC}, .nbuffers = 2, .modes = {STARPU_R, STARPU_RW}, .model = &chol_model_21, .color = 0x8080ff, }; static struct starpu_codelet cl22 = { .cpu_funcs = {chol_cpu_codelet_update_u22}, #ifdef STARPU_USE_CUDA .cuda_funcs = {chol_cublas_codelet_update_u22}, #elif defined(STARPU_SIMGRID) .cuda_funcs = {(void*)1}, #endif .cuda_flags = {STARPU_CUDA_ASYNC}, .nbuffers = 3, .modes = {STARPU_R, STARPU_R, STARPU_RW | STARPU_COMMUTE}, .model = &chol_model_22, .color = 0x00ff00, }; static void run_cholesky(starpu_data_handle_t **data_handles, int rank, int nodes) { unsigned k, m, n; unsigned unbound_prio = STARPU_MAX_PRIO == INT_MAX && STARPU_MIN_PRIO == INT_MIN; for (k = 0; k < nblocks; k++) { starpu_iteration_push(k); starpu_mpi_task_insert(MPI_COMM_WORLD, &cl11, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k) : STARPU_MAX_PRIO, STARPU_RW, data_handles[k][k], 0); for (m = k+1; m n) { /* non-diagonal block, solve */ starpu_mpi_task_insert(MPI_COMM_WORLD, &cl21, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k - m) : (m == k+1)?STARPU_MAX_PRIO:STARPU_DEFAULT_PRIO, STARPU_R, data_handles[k][k], STARPU_RW, data_handles[m][k], 0); } else { /* diagonal block, factorize */ starpu_mpi_task_insert(MPI_COMM_WORLD, &cl11, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k) : STARPU_MAX_PRIO, STARPU_RW, data_handles[k][k], 0); } } starpu_iteration_pop(); } /* Submit flushes, StarPU will fit them according to the progress */ starpu_mpi_cache_flush_all_data(MPI_COMM_WORLD); for (m = 0; m < nblocks; m++) for (n = 0; n < nblocks ; n++) starpu_data_wont_use(data_handles[m][n]); } /* TODO: generate from compiler polyhedral analysis of classical algorithm */ static void run_cholesky_antidiagonal(starpu_data_handle_t **data_handles, int rank, int nodes) { unsigned a, c; unsigned k, m, n; unsigned unbound_prio = STARPU_MAX_PRIO == INT_MAX && STARPU_MIN_PRIO == INT_MIN; /* double-antidiagonal number: * - a=0 contains (0,0) plus (1,0) * - a=1 contains (2,0), (1,1) plus (3,0), (2, 1) * - etc. */ for (a = 0; a < nblocks; a++) { starpu_iteration_push(a); unsigned nfirst; if (2*a < nblocks) nfirst = 0; else nfirst = 2*a - (nblocks-1); /* column within first antidiagonal for a */ for (n = nfirst; n <= a; n++) { /* row */ m = 2*a-n; /* Accumulate updates from TRSMs */ for (k = 0; k < n; k++) { starpu_mpi_task_insert(MPI_COMM_WORLD, &cl22, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k - m - n) : ((n == k+1) && (m == k+1))?STARPU_MAX_PRIO:STARPU_DEFAULT_PRIO, STARPU_R, data_handles[n][k], STARPU_R, data_handles[m][k], STARPU_RW | STARPU_COMMUTE, data_handles[m][n], 0); } /* k = n */ if (n < a) { /* non-diagonal block, solve */ starpu_mpi_task_insert(MPI_COMM_WORLD, &cl21, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k - m) : (m == k+1)?STARPU_MAX_PRIO:STARPU_DEFAULT_PRIO, STARPU_R, data_handles[k][k], STARPU_RW, data_handles[m][k], 0); } else { /* diagonal block, factorize */ starpu_mpi_task_insert(MPI_COMM_WORLD, &cl11, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k) : STARPU_MAX_PRIO, STARPU_RW, data_handles[k][k], 0); } } /* column within second antidiagonal for a */ for (n = nfirst; n <= a; n++) { /* row */ m = 2*a-n + 1; if (m >= nblocks) /* Skip first item when even number of tiles */ continue; /* Accumulate updates from TRSMs */ for (k = 0; k < n; k++) { starpu_mpi_task_insert(MPI_COMM_WORLD, &cl22, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k - m - n) : ((n == k+1) && (m == k+1))?STARPU_MAX_PRIO:STARPU_DEFAULT_PRIO, STARPU_R, data_handles[n][k], STARPU_R, data_handles[m][k], STARPU_RW | STARPU_COMMUTE, data_handles[m][n], 0); } /* non-diagonal block, solve */ k = n; starpu_mpi_task_insert(MPI_COMM_WORLD, &cl21, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k - m) : (m == k+1)?STARPU_MAX_PRIO:STARPU_DEFAULT_PRIO, STARPU_R, data_handles[k][k], STARPU_RW, data_handles[m][k], 0); } starpu_iteration_pop(); } /* Submit flushes, StarPU will fit them according to the progress */ starpu_mpi_cache_flush_all_data(MPI_COMM_WORLD); for (m = 0; m < nblocks; m++) for (n = 0; n < nblocks ; n++) starpu_data_wont_use(data_handles[m][n]); } /* TODO: generate from compiler polyhedral analysis of classical algorithm */ static void run_cholesky_prio(starpu_data_handle_t **data_handles, int rank, int nodes) { unsigned a; int k, m, n; unsigned unbound_prio = STARPU_MAX_PRIO == INT_MAX && STARPU_MIN_PRIO == INT_MIN; /* * This is basically similar to above, except that we shift k according to the priorities set in the algorithm, so that prio ~ 2*a or 2*a+1 * double-antidiagonal number: * - a=0 contains (0,0) plus (1,0) * - a=1 contains (2,0), (1,1) plus (3,0), (2, 1) * - etc. */ for (a = 0; a < 4*nblocks; a++) { starpu_iteration_push(a); for (k = 0; k < nblocks; k++) { n = k; /* Should be m = a-k-n; for potrf and trsm to respect priorities, but needs to be this for dependencies */ m = a-2*k-n; if (m < 0 || m >= nblocks) continue; if (m == n) { /* diagonal block, factorize */ starpu_mpi_task_insert(MPI_COMM_WORLD, &cl11, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k) : STARPU_MAX_PRIO, STARPU_RW, data_handles[k][k], 0); } else { /* non-diagonal block, solve */ starpu_mpi_task_insert(MPI_COMM_WORLD, &cl21, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k - m) : (m == k+1)?STARPU_MAX_PRIO:STARPU_DEFAULT_PRIO, STARPU_R, data_handles[k][k], STARPU_RW, data_handles[m][k], 0); } /* column within antidiagonal for a */ for (n = k + 1; n < nblocks; n++) { /* row */ m = a-2*k-n; if (m >= n && m < nblocks) { /* Update */ starpu_mpi_task_insert(MPI_COMM_WORLD, &cl22, STARPU_PRIORITY, noprio ? STARPU_DEFAULT_PRIO : unbound_prio ? (int)(2*nblocks - 2*k - m - n) : ((n == k+1) && (m == k+1))?STARPU_MAX_PRIO:STARPU_DEFAULT_PRIO, STARPU_R, data_handles[n][k], STARPU_R, data_handles[m][k], STARPU_RW | STARPU_COMMUTE, data_handles[m][n], 0); } } } starpu_iteration_pop(); } /* Submit flushes, StarPU will fit them according to the progress */ starpu_mpi_cache_flush_all_data(MPI_COMM_WORLD); for (m = 0; m < nblocks; m++) for (n = 0; n < nblocks ; n++) starpu_data_wont_use(data_handles[m][n]); } /* * code to bootstrap the factorization * and construct the DAG */ void dw_cholesky(float ***matA, unsigned ld, int rank, int nodes, double *timing, double *flops) { double start; double end; starpu_data_handle_t **data_handles; unsigned k, m, n; /* create all the DAG nodes */ data_handles = malloc(nblocks*sizeof(starpu_data_handle_t *)); for(m=0 ; m mm) { rmat[mm+nn*size] = 0.0f; // debug } } } float *test_mat = malloc(size*size*sizeof(float)); STARPU_ASSERT(test_mat); STARPU_SSYRK("L", "N", size, size, 1.0f, rmat, size, 0.0f, test_mat, size); FPRINTF(stderr, "[%d] comparing results ...\n", rank); if (display) { for (mm = 0; mm < size; mm++) { for (nn = 0; nn < size; nn++) { if (nn <= mm) { printf("%2.2f\t", test_mat[mm +nn*size]); } else { printf(".\t"); } } printf("\n"); } } *correctness = 1; for(n = 0; n < nblocks ; n++) { for (m = 0; m < nblocks; m++) { for (nn = BLOCKSIZE*n ; nn < BLOCKSIZE*(n+1); nn++) { for (mm = BLOCKSIZE*m ; mm < BLOCKSIZE*(m+1); mm++) { if (nn <= mm) { float orig = (1.0f/(1.0f+nn+mm)) + ((nn == mm)?1.0f*size:0.0f); float err = fabsf(test_mat[mm +nn*size] - orig) / orig; if (err > epsilon) { FPRINTF(stderr, "[%d] Error[%u, %u] --> %2.20f != %2.20f (err %2.20f)\n", rank, nn, mm, test_mat[mm +nn*size], orig, err); *correctness = 0; *flops = 0; break; } } } } } } free(rmat); free(test_mat); }