runtime_descriptor.c 7.12 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1 2 3 4 5 6
/**
 *
 * @copyright (c) 2009-2015 The University of Tennessee and The University
 *                          of Tennessee Research Foundation.
 *                          All rights reserved.
 * @copyright (c) 2012-2015 Inria. All rights reserved.
7
 * @copyright (c) 2012-2016 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
Mathieu Faverge's avatar
Mathieu Faverge committed
8 9 10
 *
 **/
#include <stdlib.h>
11
#include "chameleon_parsec.h"
Mathieu Faverge's avatar
Mathieu Faverge committed
12
#include <dague/data.h>
Mathieu Faverge's avatar
Mathieu Faverge committed
13

14 15 16 17 18
void RUNTIME_user_tag_size(int user_tag_width, int user_tag_sep) {
  (void)user_tag_width;
  (void)user_tag_sep;
}

19 20 21 22 23 24 25 26 27 28 29 30
void *RUNTIME_mat_alloc( size_t size)
{
    return malloc(size);
}

void RUNTIME_mat_free( void *mat, size_t size)
{
    (void)size;
    free(mat);
    return;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
31 32 33 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
struct morse_parsec_desc_s {
    dague_ddesc_t  super;
    MORSE_desc_t  *desc;
    dague_data_t **data_map;
};

static void
morse_parsec_key_to_coordinates(dague_ddesc_t *ddesc, dague_data_key_t key,
                                int *m, int *n)
{
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)ddesc;
    MORSE_desc_t *mdesc = pdesc->desc;
    int _m, _n;

    _m = key % mdesc->lmt;
    _n = key / mdesc->lmt;
    *m = _m - mdesc->i / mdesc->mb;
    *n = _n - mdesc->j / mdesc->nb;
}

static dague_data_key_t
morse_parsec_data_key(dague_ddesc_t *ddesc, ...)
{
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)ddesc;
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
    va_start(ap, ddesc);
    m = va_arg(ap, unsigned int);
    n = va_arg(ap, unsigned int);
    va_end(ap);

    /* Offset by (i,j) to translate (m,n) in the global matrix */
    m += mdesc->i / mdesc->mb;
    n += mdesc->j / mdesc->nb;

    return ((n * mdesc->lmt) + m);
}

static uint32_t
morse_parsec_rank_of(dague_ddesc_t *ddesc, ...)
{
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)ddesc;
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
    va_start(ap, ddesc);
    m = va_arg(ap, unsigned int);
    n = va_arg(ap, unsigned int);
    va_end(ap);

    /* Offset by (i,j) to translate (m,n) in the global matrix */
    m += mdesc->i / mdesc->mb;
    n += mdesc->j / mdesc->nb;

    return mdesc->get_rankof( mdesc, m, n );
}

static uint32_t
morse_parsec_rank_of_key(dague_ddesc_t *ddesc, dague_data_key_t key)
{
    int m, n;
    morse_parsec_key_to_coordinates(ddesc, key, &m, &n);
    return morse_parsec_rank_of(ddesc, m, n);
}

static int32_t
morse_parsec_vpid_of(dague_ddesc_t *ddesc, ...)
{
    return 0;
}

static int32_t
morse_parsec_vpid_of_key(dague_ddesc_t *ddesc, dague_data_key_t key)
{
    int m, n;
    morse_parsec_key_to_coordinates(ddesc, key, &m, &n);
    return morse_parsec_vpid_of(ddesc, m, n);
}

static dague_data_t*
morse_parsec_data_of(dague_ddesc_t *ddesc, ...)
{
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)ddesc;
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
    va_start(ap, ddesc);
    m = va_arg(ap, unsigned int);
    n = va_arg(ap, unsigned int);
    va_end(ap);

    /* Offset by (i,j) to translate (m,n) in the global matrix */
    m += mdesc->i / mdesc->mb;
    n += mdesc->j / mdesc->nb;

#if defined(CHAMELEON_USE_MPI)
    /* TODO: change displacement in data_map when in distributed */
    assert( mdesc->nodes == 1 );
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
137 138 139 140
    return dague_data_create( pdesc->data_map + n * mdesc->lmt + m, ddesc,
                              morse_parsec_data_key( ddesc, m, n ),
                              mdesc->get_blkaddr( mdesc, m, n ),
                              mdesc->bsiz * MORSE_Element_Size(mdesc->dtyp) );
Mathieu Faverge's avatar
Mathieu Faverge committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154
}

static dague_data_t*
morse_parsec_data_of_key(dague_ddesc_t *ddesc, dague_data_key_t key)
{
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)ddesc;
    MORSE_desc_t *mdesc = pdesc->desc;
    int m, n;
    morse_parsec_key_to_coordinates(ddesc, key, &m, &n);

#if defined(CHAMELEON_USE_MPI)
    /* TODO: change displacement in data_map when in distributed */
    assert( mdesc->nodes == 1 );
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
155 156 157
    return dague_data_create( pdesc->data_map + key, ddesc, key,
                              mdesc->get_blkaddr( mdesc, m, n ),
                              mdesc->bsiz * MORSE_Element_Size(mdesc->dtyp) );
Mathieu Faverge's avatar
Mathieu Faverge committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 203 204 205 206 207 208 209 210 211 212 213 214
}

#ifdef DAGUE_PROF_TRACE
static int
morse_parsec_key_to_string(dague_ddesc_t *ddesc, dague_data_key_t key, char * buffer, uint32_t buffer_size)
{
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)ddesc;
    MORSE_desc_t *mdesc = pdesc->desc;
    int m, n, res;
    morse_parsec_key_to_coordinates(ddesc, key, &m, &n);
    res = snprintf(buffer, buffer_size, "(%d, %d)", m, n);
    if (res < 0)
    {
        printf("error in key_to_string for tile (%u, %u) key: %u\n", m, n, datakey);
    }
    return res;
}
#endif

void RUNTIME_desc_init( MORSE_desc_t *mdesc )
{
    (void)mdesc;
    return;
}

void RUNTIME_desc_create( MORSE_desc_t *mdesc )
{
    dague_ddesc_t       *ddesc;
    morse_parsec_desc_t *pdesc;
    int comm_size;

    pdesc = malloc( sizeof(morse_parsec_desc_t) );
    ddesc = (dague_ddesc_t*)pdesc;

    /* Super setup */
    RUNTIME_comm_size( &comm_size );
    ddesc->nodes  = comm_size;
    ddesc->myrank = mdesc->myrank;

    ddesc->data_key    = morse_parsec_data_key;
    ddesc->rank_of     = morse_parsec_rank_of;
    ddesc->rank_of_key = morse_parsec_rank_of_key;
    ddesc->data_of     = morse_parsec_data_of;
    ddesc->data_of_key = morse_parsec_data_of_key;
    ddesc->vpid_of     = morse_parsec_vpid_of;
    ddesc->vpid_of_key = morse_parsec_vpid_of_key;
#if defined(DAGUE_PROF_TRACE)
    {
        int rc;
        ddesc->key_to_string = morse_parsec_key_to_string;
        ddesc->key           = NULL;
        rc = asprintf(&(ddesc->key_dim), "(%d, %d)", mdesc->lmt, mdesc->lnt);
        (void)rc;
    }
#endif
    ddesc->memory_registration_status = MEMORY_STATUS_UNREGISTERED;

Mathieu Faverge's avatar
Mathieu Faverge committed
215
    pdesc->data_map = calloc( mdesc->lmt * mdesc->lnt, sizeof(dague_data_t*) );
Mathieu Faverge's avatar
Mathieu Faverge committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237

    /* Double linking */
    pdesc->desc     = mdesc;
    mdesc->schedopt = pdesc;

    /* /\* Overwrite the leading dimensions to store the padding *\/ */
    /* mdesc->llm = mdesc->mb * mdesc->lmt; */
    /* mdesc->lln = mdesc->nb * mdesc->lnt; */
    return;
}

void RUNTIME_desc_destroy( MORSE_desc_t *mdesc )
{
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)(mdesc->schedopt);

    if ( pdesc->data_map != NULL ) {
        dague_data_t **data = pdesc->data_map;
        int nb_local_tiles = mdesc->lmt * mdesc->lnt;
        int i;

        for(i=0; i<nb_local_tiles; i++, data++)
        {
Mathieu Faverge's avatar
Mathieu Faverge committed
238
            dague_data_destroy( *data );
Mathieu Faverge's avatar
Mathieu Faverge committed
239 240 241 242 243
        }

        free( pdesc->data_map );
        pdesc->data_map = NULL;
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
244
    free(pdesc);
Mathieu Faverge's avatar
Mathieu Faverge committed
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
    return;
}

void RUNTIME_desc_submatrix( MORSE_desc_t *desc )
{
    (void)desc;
    return;
}

int RUNTIME_desc_acquire( MORSE_desc_t *desc )
{
    (void)desc;
    return MORSE_SUCCESS;
}

int RUNTIME_desc_release( MORSE_desc_t *desc )
{
    (void)desc;
    return MORSE_SUCCESS;
}

int RUNTIME_desc_getoncpu( MORSE_desc_t *desc )
{
    (void)desc;
    return MORSE_SUCCESS;
}

272
void *RUNTIME_desc_getaddr( const MORSE_desc_t *desc, int m, int n )
Mathieu Faverge's avatar
Mathieu Faverge committed
273 274 275 276
{
    assert(0); /* This should not be called because we also need the handle to match the address we need. */
    return desc->get_blkaddr( desc, m, n );
}