Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

codelet_ztstrf.c 8.42 KB
Newer Older
1 2
/**
 *
3 4
 * @copyright (c) 2009-2014 The University of Tennessee and The University
 *                          of Tennessee Research Foundation.
5 6
 *                          All rights reserved.
 * @copyright (c) 2012-2014 Inria. All rights reserved.
7
 * @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 **/

/**
 *
 * @file codelet_ztstrf.c
 *
 *  MORSE codelets kernel
 *  MORSE is a software package provided by Univ. of Tennessee,
 *  Univ. of California Berkeley and Univ. of Colorado Denver
 *
 * @version 2.5.0
 * @comment This file has been automatically generated
 *          from Plasma 2.5.0 for MORSE 1.0.0
 * @author Hatem Ltaief
 * @author Jakub Kurzak
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> c d s
 *
 **/
31
#include "runtime/starpu/include/morse_starpu.h"
32
#include "runtime/starpu/include/runtime_codelet_z.h"
33
#include "coreblas/include/cblas.h"
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
#include <math.h>

/**
 *
 * @ingroup CORE_MORSE_Complex64_t
 *
 *  CORE_ztstrf computes an LU factorization of a complex matrix formed
 *  by an upper triangular NB-by-N tile U on top of a M-by-N tile A
 *  using partial pivoting with row interchanges.
 *
 *  This is the right-looking Level 2.5 BLAS version of the algorithm.
 *
 *******************************************************************************
 *
 * @param[in] M
 *         The number of rows of the tile A.  M >= 0.
 *
 * @param[in] N
 *         The number of columns of the tile A.  N >= 0.
 *
 * @param[in] IB
 *         The inner-blocking size.  IB >= 0.
 *
 * @param[in] NB
 *
 * @param[in,out] U
 *         On entry, the NB-by-N upper triangular tile.
 *         On exit, the new factor U from the factorization
 *
 * @param[in] LDU
 *         The leading dimension of the array U.  LDU >= max(1,NB).
 *
 * @param[in,out] A
 *         On entry, the M-by-N tile to be factored.
 *         On exit, the factor L from the factorization
 *
 * @param[in] LDA
 *         The leading dimension of the array A.  LDA >= max(1,M).
 *
 * @param[in,out] L
 *         On entry, the IB-by-N lower triangular tile.
 *         On exit, the interchanged rows form the tile A in case of pivoting.
 *
 * @param[in] LDL
 *         The leading dimension of the array L.  LDL >= max(1,IB).
 *
 * @param[out] IPIV
 *         The pivot indices; for 1 <= i <= min(M,N), row i of the
 *         tile U was interchanged with row IPIV(i) of the tile A.
 *
 * @param[in,out] WORK
 *
 * @param[in] LDWORK
 *         The dimension of the array WORK.
 *
 * @param[out] INFO
 *
 *******************************************************************************
 *
 * @return
 *         \retval MORSE_SUCCESS successful exit
 *         \retval <0 if INFO = -k, the k-th argument had an illegal value
 *         \retval >0 if INFO = k, U(k,k) is exactly zero. The factorization
 *              has been completed, but the factor U is exactly
 *              singular, and division by zero will occur if it is used
 *              to solve a system of equations.
 *
 ******************************************************************************/

void MORSE_TASK_ztstrf(MORSE_option_t *options,
                       int m, int n, int ib, int nb,
                       MORSE_desc_t *U, int Um, int Un, int ldu,
                       MORSE_desc_t *A, int Am, int An, int lda,
                       MORSE_desc_t *L, int Lm, int Ln, int ldl,
                       int *IPIV,
                       MORSE_bool check_info, int iinfo)
{
    (void)nb;
    struct starpu_codelet *codelet = &cl_ztstrf;
    void (*callback)(void*) = options->profiling ? cl_ztstrf_callback : NULL;
    MORSE_starpu_ws_t *d_work = (MORSE_starpu_ws_t*)(options->ws_host);

    if ( morse_desc_islocal( U, Um, Un ) ||
         morse_desc_islocal( A, Am, An ) ||
         morse_desc_islocal( L, Lm, Ln ) )
    {
        starpu_insert_task(
            codelet,
            STARPU_VALUE,    &m,                         sizeof(int),
            STARPU_VALUE,    &n,                         sizeof(int),
            STARPU_VALUE,    &ib,                        sizeof(int),
            STARPU_VALUE,    &nb,                        sizeof(int),
            STARPU_RW,        RTBLKADDR(U, MORSE_Complex64_t, Um, Un),
            STARPU_VALUE,    &ldu,                       sizeof(int),
            STARPU_RW,        RTBLKADDR(A, MORSE_Complex64_t, Am, An),
            STARPU_VALUE,    &lda,                       sizeof(int),
            STARPU_W,         RTBLKADDR(L, MORSE_Complex64_t, Lm, Ln),
            STARPU_VALUE,    &ldl,                       sizeof(int),
            STARPU_VALUE,    &IPIV,                      sizeof(int*),
            STARPU_SCRATCH,   options->ws_worker,
            STARPU_VALUE,    &d_work,                    sizeof(MORSE_starpu_ws_t *),
            STARPU_VALUE,    &nb,                        sizeof(int),
            STARPU_VALUE,    &check_info,                sizeof(MORSE_bool),
            STARPU_VALUE,    &iinfo,                     sizeof(int),
            STARPU_PRIORITY,  options->priority,
            STARPU_CALLBACK,  callback,
            0);
    }
}


static void cl_ztstrf_cpu_func(void *descr[], void *cl_arg)
{
    MORSE_starpu_ws_t *d_work;
    int m;
    int n;
    int ib;
    int nb;
    MORSE_Complex64_t *U;
    int ldu;
    MORSE_Complex64_t *A;
    int lda;
    MORSE_Complex64_t *L;
    int ldl;
    int *IPIV;
    MORSE_Complex64_t *WORK;
    int ldwork;
    MORSE_bool check_info;
    int iinfo;

    int info = 0;

    U = (MORSE_Complex64_t *)STARPU_MATRIX_GET_PTR(descr[0]);
    A = (MORSE_Complex64_t *)STARPU_MATRIX_GET_PTR(descr[1]);
    L = (MORSE_Complex64_t *)STARPU_MATRIX_GET_PTR(descr[2]);
    WORK = (MORSE_Complex64_t *)STARPU_MATRIX_GET_PTR(descr[3]);

    starpu_codelet_unpack_args(cl_arg, &m, &n, &ib, &nb, &ldu, &lda, &ldl, &IPIV, &d_work, &ldwork, &check_info, &iinfo);

    CORE_ztstrf(m, n, ib, nb, U, ldu, A, lda, L, ldl, IPIV, WORK, ldwork, &info);

175
#if defined(CHAMELEON_USE_MAGMA)
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    /*
     * L stores the following if enough place:
     *      L1     L2    L3     ...
     *      L1^-1  L2^-1 L3^-1  ...
     */
    /* Compute L-1 in lower rectangle of L */
    if ( ldl >= 2*ib )
    {
        int i, sb;
        for (i=0; i<n; i+=ib) {
            sb = min( ib, n-i );
            CORE_zlacpy(MorseUpperLower, sb, sb, L+(i*ldl), ldl, L+(i*ldl)+ib, ldl );

            CORE_ztrtri( MorseLower, MorseUnit, sb, L+(i*ldl)+ib, ldl, &info );
            if (info != 0 ) {
                fprintf(stderr, "ERROR, trtri returned with info = %d\n", info);
            }
        }
    }
#endif
}


/*
 * Codelet GPU
 */
/* TODO/WARNING: tstrf is not working on GPU for now */
203
#if defined(CHAMELEON_USE_MAGMA) && 0
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
static void cl_ztstrf_cuda_func(void *descr[], void *cl_arg)
{
    MORSE_starpu_ws_t *d_work;
    int m;
    int n;
    int ib;
    int nb;
    cuDoubleComplex *hU, *dU;
    int ldu;
    cuDoubleComplex *hA, *dA;
    int lda;
    cuDoubleComplex *hL, *dL;
    int ldl;
    int *ipiv;
    cuDoubleComplex *hw2, *hw, *dw;
    int ldwork;
    MORSE_bool check_info;
    int iinfo;
    int info;

    starpu_codelet_unpack_args(cl_arg, &m, &n, &ib, &nb, &ldu, &lda, &ldl, &ipiv,
			       &d_work, &ldwork, &check_info, &iinfo);

    dU = (cuDoubleComplex *)STARPU_MATRIX_GET_PTR(descr[0]);
    dA = (cuDoubleComplex *)STARPU_MATRIX_GET_PTR(descr[1]);
    dL = (cuDoubleComplex *)STARPU_MATRIX_GET_PTR(descr[2]);

    /*
     *  hwork => 2*nb*(2*ib+2nb)
     *  dwork => 2*ib*nb
     */
    hw2 = (cuDoubleComplex *)STARPU_MATRIX_GET_PTR(descr[3]);
    dw  = (cuDoubleComplex*)RUNTIME_starpu_ws_getlocal(d_work);

    hU = hw2;
    hA = hU + ldu * nb;
    hL = hA + lda * nb;
    hw = hL + ldl * nb;

    /* Download first panel from A and U */
    cublasGetMatrix( nb, n,  sizeof(cuDoubleComplex), dU, ldu, hU, ldu );
    cublasGetMatrix( m,  ib, sizeof(cuDoubleComplex), dA, lda, hA, lda );

    /* Initialize L to 0 */
    memset(hL, 0, ldl*nb*sizeof(cuDoubleComplex));

    magma_ztstrf_gpu( MagmaColMajor, m, n, ib, nb,
                      hU, ldu, dU, ldu,
                      hA, lda, dA, lda,
                      hL, ldl, dL, ldl,
                      ipiv,
                      hw, ldwork, dw, lda,
                      &info );

    cudaThreadSynchronize();
}
#endif

/*
 * Codelet definition
 */
265
#if (defined(CHAMELEON_USE_MAGMA) && 0) || defined(CHAMELEON_SIMULATION)
266 267 268 269 270
CODELETS(ztstrf, 4, cl_ztstrf_cpu_func, cl_ztstrf_cuda_func, 0)
#else
CODELETS_CPU(ztstrf, 4, cl_ztstrf_cpu_func)
#endif