codelet_zgemm.c 5.32 KB
Newer Older
1 2
/**
 *
3 4
 * @copyright (c) 2009-2014 The University of Tennessee and The University
 *                          of Tennessee Research Foundation.
5
 *                          All rights reserved.
6
 * @copyright (c) 2012-2016 Inria. All rights reserved.
7
 * @copyright (c) 2012-2014, 2016 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_zgemm.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 32
#include "chameleon_starpu.h"
#include "runtime_codelet_z.h"
33 34 35 36 37 38 39

/**
 *
 * @ingroup CORE_MORSE_Complex64_t
 *
 **/

40
void MORSE_TASK_zgemm(const MORSE_option_t *options,
41 42
                      MORSE_enum transA, int transB,
                      int m, int n, int k, int nb,
43 44 45
                      MORSE_Complex64_t alpha, const MORSE_desc_t *A, int Am, int An, int lda,
                                               const MORSE_desc_t *B, int Bm, int Bn, int ldb,
                      MORSE_Complex64_t beta,  const MORSE_desc_t *C, int Cm, int Cn, int ldc)
46 47 48 49
{
    (void)nb;
    struct starpu_codelet *codelet = &cl_zgemm;
    void (*callback)(void*) = options->profiling ? cl_zgemm_callback : NULL;
50 51 52
    int sizeA = lda*k;
    int sizeB = ldb*n;
    int sizeC = ldc*n;
53 54
    int execution_rank = C->get_rankof( C, Cm, Cn );
    int rank_changed=0;
55
    (void)execution_rank;
56

57
    /*  force execution on the rank owning the largest data (tile) */
58 59
    int threshold;
    char* env = getenv("MORSE_COMM_FACTOR_THRESHOLD");
60

61 62 63 64 65
    if (env != NULL)
        threshold = (unsigned)atoi(env);
    else
        threshold = 10;
    if ( sizeA > threshold*sizeC ){
66 67
        execution_rank = A->get_rankof( A, Am, An );
        rank_changed = 1;
68
    }else if( sizeB > threshold*sizeC ){
69 70 71
        execution_rank = B->get_rankof( B, Bm, Bn );
        rank_changed = 1;
    }
72

73 74 75 76 77
    MORSE_BEGIN_ACCESS_DECLARATION;
    MORSE_ACCESS_R(A, Am, An);
    MORSE_ACCESS_R(B, Bm, Bn);
    MORSE_ACCESS_RW(C, Cm, Cn);
    if (rank_changed)
78
        MORSE_RANK_CHANGED(execution_rank);
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    MORSE_END_ACCESS_DECLARATION;

    starpu_insert_task(
        starpu_mpi_codelet(codelet),
        STARPU_VALUE,    &transA,            sizeof(MORSE_enum),
        STARPU_VALUE,    &transB,            sizeof(MORSE_enum),
        STARPU_VALUE,    &m,                 sizeof(int),
        STARPU_VALUE,    &n,                 sizeof(int),
        STARPU_VALUE,    &k,                 sizeof(int),
        STARPU_VALUE,    &alpha,             sizeof(MORSE_Complex64_t),
        STARPU_R,         RTBLKADDR(A, MORSE_Complex64_t, Am, An),
        STARPU_VALUE,    &lda,               sizeof(int),
        STARPU_R,         RTBLKADDR(B, MORSE_Complex64_t, Bm, Bn),
        STARPU_VALUE,    &ldb,               sizeof(int),
        STARPU_VALUE,    &beta,              sizeof(MORSE_Complex64_t),
        STARPU_RW,        RTBLKADDR(C, MORSE_Complex64_t, Cm, Cn),
        STARPU_VALUE,    &ldc,               sizeof(int),
        STARPU_PRIORITY,  options->priority,
        STARPU_CALLBACK,  callback,
98
#if defined(CHAMELEON_USE_MPI)
99
        STARPU_EXECUTE_ON_NODE, execution_rank,
100 101
#endif
#if defined(CHAMELEON_CODELETS_HAVE_NAME)
102
        STARPU_NAME, "zgemm",
103
#endif
104
        0);
105 106
}

107
#if !defined(CHAMELEON_SIMULATION)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
static void cl_zgemm_cpu_func(void *descr[], void *cl_arg)
{
    MORSE_enum transA;
    MORSE_enum transB;
    int m;
    int n;
    int k;
    MORSE_Complex64_t alpha;
    MORSE_Complex64_t *A;
    int lda;
    MORSE_Complex64_t *B;
    int ldb;
    MORSE_Complex64_t beta;
    MORSE_Complex64_t *C;
    int ldc;

    A = (MORSE_Complex64_t *)STARPU_MATRIX_GET_PTR(descr[0]);
    B = (MORSE_Complex64_t *)STARPU_MATRIX_GET_PTR(descr[1]);
    C = (MORSE_Complex64_t *)STARPU_MATRIX_GET_PTR(descr[2]);
    starpu_codelet_unpack_args(cl_arg, &transA, &transB, &m, &n, &k, &alpha, &lda, &ldb, &beta, &ldc);
128
    CORE_zgemm(transA, transB,
129
        m, n, k,
130
        alpha, A, lda,
131
        B, ldb,
132
        beta, C, ldc);
133 134
}

135
#ifdef CHAMELEON_USE_CUDA
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
static void cl_zgemm_cuda_func(void *descr[], void *cl_arg)
{
    MORSE_enum transA;
    MORSE_enum transB;
    int m;
    int n;
    int k;
    cuDoubleComplex alpha;
    const cuDoubleComplex *A;
    int lda;
    const cuDoubleComplex *B;
    int ldb;
    cuDoubleComplex beta;
    cuDoubleComplex *C;
    int ldc;

    A = (const cuDoubleComplex *)STARPU_MATRIX_GET_PTR(descr[0]);
    B = (const cuDoubleComplex *)STARPU_MATRIX_GET_PTR(descr[1]);
    C = (cuDoubleComplex *)STARPU_MATRIX_GET_PTR(descr[2]);
    starpu_codelet_unpack_args(cl_arg, &transA, &transB, &m, &n, &k, &alpha, &lda, &ldb, &beta, &ldc);

Mathieu Faverge's avatar
Mathieu Faverge committed
157
    RUNTIME_getStream( stream );
158

159 160
    CUDA_zgemm(
        transA, transB,
161
        m, n, k,
162 163 164 165
        &alpha, A, lda,
                B, ldb,
        &beta,  C, ldc,
        stream);
166 167 168 169 170 171 172

#ifndef STARPU_CUDA_ASYNC
    cudaStreamSynchronize( stream );
#endif

    return;
}
173
#endif /* defined(CHAMELEON_USE_CUDA) */
174
#endif /* !defined(CHAMELEON_SIMULATION) */
175 176 177 178

/*
 * Codelet definition
 */
179
CODELETS(zgemm, 3, cl_zgemm_cpu_func, cl_zgemm_cuda_func, STARPU_CUDA_ASYNC)