runtime_descriptor.c 11 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1
/**
2 3
 *
 * @file runtime_descriptor.c
Mathieu Faverge's avatar
Mathieu Faverge committed
4
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
5
 * @copyright 2012-2017 The University of Tennessee and The University of
Mathieu Faverge's avatar
Mathieu Faverge committed
6
 *                      Tennessee Research Foundation. All rights reserved.
Mathieu Faverge's avatar
Mathieu Faverge committed
7 8 9
 * @copyright 2012-2017 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                      Univ. Bordeaux. All rights reserved.
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10 11 12 13
 ***
 *
 * @brief Chameleon PaRSEC descriptor routines
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14 15 16 17
 * @version 1.0.0
 * @author Reazul Hoque
 * @author Mathieu Faverge
 * @date 2017-01-12
Mathieu Faverge's avatar
Mathieu Faverge committed
18 19 20
 *
 **/
#include <stdlib.h>
21
#include "chameleon_parsec.h"
Mathieu Faverge's avatar
Mathieu Faverge committed
22 23
#include <parsec/data.h>
#include <parsec/datatype.h>
Mathieu Faverge's avatar
Mathieu Faverge committed
24
//#include <parsec/data_dist/matrix/matrix.h>
Mathieu Faverge's avatar
Mathieu Faverge committed
25 26 27
#include <parsec/arena.h>

static int parsec_global_arena_index = 0;
Mathieu Faverge's avatar
Mathieu Faverge committed
28

Mathieu Faverge's avatar
Mathieu Faverge committed
29 30 31 32 33
void RUNTIME_comm_set_tag_sizes( int user_tag_width,
                                 int user_tag_sep )
{
    (void)user_tag_width;
    (void)user_tag_sep;
34 35
}

Mathieu Faverge's avatar
Mathieu Faverge committed
36
void *RUNTIME_malloc( size_t size )
37 38 39 40
{
    return malloc(size);
}

Mathieu Faverge's avatar
Mathieu Faverge committed
41
void RUNTIME_free( void *ptr, size_t size )
42 43
{
    (void)size;
Mathieu Faverge's avatar
Mathieu Faverge committed
44
    free(ptr);
45 46 47
    return;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
48
struct morse_parsec_desc_s {
Mathieu Faverge's avatar
Mathieu Faverge committed
49
    parsec_data_collection_t  super;
Mathieu Faverge's avatar
Mathieu Faverge committed
50
    MORSE_desc_t  *desc;
Mathieu Faverge's avatar
Mathieu Faverge committed
51 52
    parsec_data_t **data_map;
    int arena_index;
Mathieu Faverge's avatar
Mathieu Faverge committed
53 54
};

Mathieu Faverge's avatar
Mathieu Faverge committed
55 56
int
morse_parsec_get_arena_index(const MORSE_desc_t *desc) {
57 58 59
    return ((morse_parsec_desc_t *)desc->schedopt)->arena_index;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
60
static inline void
Mathieu Faverge's avatar
Mathieu Faverge committed
61
morse_parsec_key_to_coordinates(parsec_data_collection_t *data_collection, parsec_data_key_t key,
Mathieu Faverge's avatar
Mathieu Faverge committed
62 63
                                int *m, int *n)
{
Mathieu Faverge's avatar
Mathieu Faverge committed
64
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
65 66 67 68 69 70 71 72 73
    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;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
74
static inline parsec_data_key_t
Mathieu Faverge's avatar
Mathieu Faverge committed
75
morse_parsec_data_key(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
76
{
Mathieu Faverge's avatar
Mathieu Faverge committed
77
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
78 79 80 81 82
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
Mathieu Faverge's avatar
Mathieu Faverge committed
83
    va_start(ap, data_collection);
Mathieu Faverge's avatar
Mathieu Faverge committed
84 85 86 87 88 89 90 91 92 93 94
    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);
}

Mathieu Faverge's avatar
Mathieu Faverge committed
95
static inline uint32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
96
morse_parsec_rank_of(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
97
{
Mathieu Faverge's avatar
Mathieu Faverge committed
98
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
99 100 101 102 103
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
Mathieu Faverge's avatar
Mathieu Faverge committed
104
    va_start(ap, data_collection);
Mathieu Faverge's avatar
Mathieu Faverge committed
105 106 107 108 109 110 111 112 113 114 115
    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 );
}

Mathieu Faverge's avatar
Mathieu Faverge committed
116
static inline uint32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
117
morse_parsec_rank_of_key(parsec_data_collection_t *data_collection, parsec_data_key_t key)
Mathieu Faverge's avatar
Mathieu Faverge committed
118 119
{
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
120 121
    morse_parsec_key_to_coordinates(data_collection, key, &m, &n);
    return morse_parsec_rank_of(data_collection, m, n);
Mathieu Faverge's avatar
Mathieu Faverge committed
122 123
}

Mathieu Faverge's avatar
Mathieu Faverge committed
124
static inline int32_t
125
morse_parsec_vpid_of(parsec_data_collection_t *data_collection, ... )
Mathieu Faverge's avatar
Mathieu Faverge committed
126
{
127
    (void)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
128 129 130
    return 0;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
131
static inline int32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
132
morse_parsec_vpid_of_key(parsec_data_collection_t *data_collection, parsec_data_key_t key)
Mathieu Faverge's avatar
Mathieu Faverge committed
133 134
{
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
135 136
    morse_parsec_key_to_coordinates(data_collection, key, &m, &n);
    return morse_parsec_vpid_of(data_collection, m, n);
Mathieu Faverge's avatar
Mathieu Faverge committed
137 138
}

Mathieu Faverge's avatar
Mathieu Faverge committed
139
static inline parsec_data_t*
Mathieu Faverge's avatar
Mathieu Faverge committed
140
morse_parsec_data_of(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
141
{
Mathieu Faverge's avatar
Mathieu Faverge committed
142
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
143 144 145 146 147
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
Mathieu Faverge's avatar
Mathieu Faverge committed
148
    va_start(ap, data_collection);
Mathieu Faverge's avatar
Mathieu Faverge committed
149 150 151 152 153 154 155 156 157 158
    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 */
Mathieu Faverge's avatar
Mathieu Faverge committed
159
    //assert( data_collection->nodes == 1 );
Mathieu Faverge's avatar
Mathieu Faverge committed
160
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
161
    return parsec_data_create( pdesc->data_map + n * mdesc->lmt + m, data_collection,
Mathieu Faverge's avatar
Mathieu Faverge committed
162 163 164
                               morse_parsec_data_key( data_collection, m, n ),
                               mdesc->get_blkaddr( mdesc, m, n ),
                               mdesc->bsiz * MORSE_Element_Size(mdesc->dtyp) );
Mathieu Faverge's avatar
Mathieu Faverge committed
165 166
}

Mathieu Faverge's avatar
Mathieu Faverge committed
167
static inline parsec_data_t*
Mathieu Faverge's avatar
Mathieu Faverge committed
168
morse_parsec_data_of_key(parsec_data_collection_t *data_collection, parsec_data_key_t key)
Mathieu Faverge's avatar
Mathieu Faverge committed
169
{
Mathieu Faverge's avatar
Mathieu Faverge committed
170
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
171 172
    MORSE_desc_t *mdesc = pdesc->desc;
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
173
    morse_parsec_key_to_coordinates(data_collection, key, &m, &n);
Mathieu Faverge's avatar
Mathieu Faverge committed
174 175 176

#if defined(CHAMELEON_USE_MPI)
    /* TODO: change displacement in data_map when in distributed */
Mathieu Faverge's avatar
Mathieu Faverge committed
177
    //assert( data_collection->nodes == 1 );
Mathieu Faverge's avatar
Mathieu Faverge committed
178
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
179
    return parsec_data_create( pdesc->data_map + key, data_collection, key,
Mathieu Faverge's avatar
Mathieu Faverge committed
180 181
                               mdesc->get_blkaddr( mdesc, m, n ),
                               mdesc->bsiz * MORSE_Element_Size(mdesc->dtyp) );
Mathieu Faverge's avatar
Mathieu Faverge committed
182 183
}

Mathieu Faverge's avatar
Mathieu Faverge committed
184
#ifdef parsec_PROF_TRACE
Mathieu Faverge's avatar
Mathieu Faverge committed
185
static inline int
Mathieu Faverge's avatar
Mathieu Faverge committed
186
morse_parsec_key_to_string(parsec_data_collection_t *data_collection, parsec_data_key_t key, char * buffer, uint32_t buffer_size)
Mathieu Faverge's avatar
Mathieu Faverge committed
187
{
Mathieu Faverge's avatar
Mathieu Faverge committed
188
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
189 190
    MORSE_desc_t *mdesc = pdesc->desc;
    int m, n, res;
Mathieu Faverge's avatar
Mathieu Faverge committed
191
    morse_parsec_key_to_coordinates(data_collection, key, &m, &n);
Mathieu Faverge's avatar
Mathieu Faverge committed
192 193 194
    res = snprintf(buffer, buffer_size, "(%d, %d)", m, n);
    if (res < 0)
    {
Mathieu Faverge's avatar
Mathieu Faverge committed
195 196
        printf("error in key_to_string for tile (%u, %u) key: %u\n",
               (unsigned int)m, (unsigned int)n, datakey);
Mathieu Faverge's avatar
Mathieu Faverge committed
197 198 199 200 201
    }
    return res;
}
#endif

Mathieu Faverge's avatar
Mathieu Faverge committed
202 203 204
/*******************************************************************************
 *  Create data descriptor
 **/
Mathieu Faverge's avatar
Mathieu Faverge committed
205 206
void RUNTIME_desc_create( MORSE_desc_t *mdesc )
{
Mathieu Faverge's avatar
Mathieu Faverge committed
207
    parsec_data_collection_t *data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
208 209 210 211
    morse_parsec_desc_t *pdesc;
    int comm_size;

    pdesc = malloc( sizeof(morse_parsec_desc_t) );
Mathieu Faverge's avatar
Mathieu Faverge committed
212
    data_collection = (parsec_data_collection_t*)pdesc;
Mathieu Faverge's avatar
Mathieu Faverge committed
213 214

    /* Super setup */
Mathieu Faverge's avatar
Mathieu Faverge committed
215
    comm_size = RUNTIME_comm_size( NULL );
Mathieu Faverge's avatar
Mathieu Faverge committed
216 217 218 219 220 221 222 223 224 225 226
    data_collection->nodes  = comm_size;
    data_collection->myrank = mdesc->myrank;

    data_collection->data_key    = morse_parsec_data_key;
    data_collection->rank_of     = morse_parsec_rank_of;
    data_collection->rank_of_key = morse_parsec_rank_of_key;
    data_collection->data_of     = morse_parsec_data_of;
    data_collection->data_of_key = morse_parsec_data_of_key;
    data_collection->vpid_of     = morse_parsec_vpid_of;
    data_collection->vpid_of_key = morse_parsec_vpid_of_key;
#if defined(parsec_PROF_TRACE)
Mathieu Faverge's avatar
Mathieu Faverge committed
227 228
    {
        int rc;
Mathieu Faverge's avatar
Mathieu Faverge committed
229 230 231
        data_collection->key_to_string = morse_parsec_key_to_string;
        data_collection->key           = NULL;
        rc = asprintf(&(data_collection->key_dim), "(%d, %d)", mdesc->lmt, mdesc->lnt);
Mathieu Faverge's avatar
Mathieu Faverge committed
232 233 234
        (void)rc;
    }
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
235
    data_collection->memory_registration_status = MEMORY_STATUS_UNREGISTERED;
Mathieu Faverge's avatar
Mathieu Faverge committed
236

Mathieu Faverge's avatar
Mathieu Faverge committed
237
    pdesc->data_map = calloc( mdesc->lmt * mdesc->lnt, sizeof(parsec_data_t*) );
Mathieu Faverge's avatar
Mathieu Faverge committed
238 239 240 241 242

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

Mathieu Faverge's avatar
Mathieu Faverge committed
243 244
    parsec_dtd_data_collection_init(data_collection);

245
    /* arena init */
Mathieu Faverge's avatar
Mathieu Faverge committed
246 247
    pdesc->arena_index = 0;

248 249 250 251 252 253 254 255 256
    /* taskpool init to bypass a requirement of PaRSEC  */
#if defined(CHAMELEON_USE_MPI)
    parsec_dtd_taskpool_new();
    /* Internal limitation of PaRSEC */
    assert(parsec_global_arena_index < 16);
    pdesc->arena_index = parsec_global_arena_index++;

    parsec_datatype_t datatype;
    switch(mdesc->dtyp) {
Mathieu Faverge's avatar
Mathieu Faverge committed
257 258 259 260 261 262
    case MorseInteger:       datatype = parsec_datatype_int32_t; break;
    case MorseRealFloat:     datatype = parsec_datatype_float_t; break;
    case MorseRealDouble:    datatype = parsec_datatype_double_t; break;
    case MorseComplexFloat:  datatype = parsec_datatype_complex_t; break;
    case MorseComplexDouble: datatype = parsec_datatype_double_complex_t; break;
    default: morse_fatal_error("MORSE_Element_Size", "undefined type"); break;
263 264 265 266
    }

    parsec_matrix_add2arena_tile( parsec_dtd_arenas[pdesc->arena_index], datatype, mdesc->mb*mdesc->nb*MORSE_Element_Size(mdesc->dtyp) );
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
267 268 269 270 271 272
    /* /\* Overwrite the leading dimensions to store the padding *\/ */
    /* mdesc->llm = mdesc->mb * mdesc->lmt; */
    /* mdesc->lln = mdesc->nb * mdesc->lnt; */
    return;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
273 274 275
/*******************************************************************************
 *  Destroy data descriptor
 **/
Mathieu Faverge's avatar
Mathieu Faverge committed
276 277 278
void RUNTIME_desc_destroy( MORSE_desc_t *mdesc )
{
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)(mdesc->schedopt);
279 280 281
    if ( pdesc == NULL ) {
        return;
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
282 283

    if ( pdesc->data_map != NULL ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
284
        parsec_data_t **data = pdesc->data_map;
Mathieu Faverge's avatar
Mathieu Faverge committed
285 286 287 288 289
        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
290
            parsec_data_destroy( *data );
Mathieu Faverge's avatar
Mathieu Faverge committed
291 292 293 294 295
        }

        free( pdesc->data_map );
        pdesc->data_map = NULL;
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
296 297 298

    parsec_dtd_data_collection_fini( (parsec_data_collection_t *)pdesc );

Mathieu Faverge's avatar
Mathieu Faverge committed
299
    free(pdesc);
300
    mdesc->schedopt = NULL;
Mathieu Faverge's avatar
Mathieu Faverge committed
301 302 303
    return;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
304 305 306 307
/*******************************************************************************
 *  Acquire data
 **/
int RUNTIME_desc_acquire( const MORSE_desc_t *desc )
Mathieu Faverge's avatar
Mathieu Faverge committed
308 309
{
    (void)desc;
Mathieu Faverge's avatar
Mathieu Faverge committed
310
    return MORSE_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
311 312
}

Mathieu Faverge's avatar
Mathieu Faverge committed
313 314 315 316
/*******************************************************************************
 *  Release data
 **/
int RUNTIME_desc_release( const MORSE_desc_t *desc )
Mathieu Faverge's avatar
Mathieu Faverge committed
317 318 319 320 321
{
    (void)desc;
    return MORSE_SUCCESS;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
322
/*******************************************************************************
Mathieu Faverge's avatar
Mathieu Faverge committed
323
 *  Flush cached data
Mathieu Faverge's avatar
Mathieu Faverge committed
324
 **/
Mathieu Faverge's avatar
Mathieu Faverge committed
325
void RUNTIME_flush()
Mathieu Faverge's avatar
Mathieu Faverge committed
326 327 328
{
}

Mathieu Faverge's avatar
Mathieu Faverge committed
329 330
void RUNTIME_desc_flush( const MORSE_desc_t     *desc,
                         const MORSE_sequence_t *sequence )
Mathieu Faverge's avatar
Mathieu Faverge committed
331
{
Mathieu Faverge's avatar
Mathieu Faverge committed
332 333 334
    parsec_taskpool_t* PARSEC_dtd_taskpool = (parsec_taskpool_t *)(sequence->schedopt);

    parsec_dtd_data_flush_all( PARSEC_dtd_taskpool, (parsec_data_collection_t*)(desc->schedopt) );
Mathieu Faverge's avatar
Mathieu Faverge committed
335
}
Mathieu Faverge's avatar
Mathieu Faverge committed
336

Mathieu Faverge's avatar
Mathieu Faverge committed
337 338 339
void RUNTIME_data_flush( const MORSE_sequence_t *sequence,
                         const MORSE_desc_t *A, int Am, int An )
{
340 341 342 343 344 345 346 347 348 349
    /*
     * For now, we do nothing in this function as in PaRSEC, once the data is
     * flushed it cannot be reused in the same sequence, when this issue will be
     * fixed, we will uncomment this function
     */
    /* parsec_taskpool_t* PARSEC_dtd_taskpool = (parsec_taskpool_t *)(sequence->schedopt); */
    /* parsec_dtd_data_flush( PARSEC_dtd_taskpool, RTBLKADDR( A, MORSE_Complex64_t, Am, An ) ); */

    (void)sequence; (void)A; (void)Am; (void)An;
    return;
Mathieu Faverge's avatar
Mathieu Faverge committed
350 351
}

352 353 354 355 356 357 358 359
#if defined(CHAMELEON_USE_MIGRATE)
void RUNTIME_data_migrate( const MORSE_sequence_t *sequence,
                           const MORSE_desc_t *A, int Am, int An, int new_rank )
{
    (void)sequence; (void)A; (void)Am; (void)An; (void)new_rank;
}
#endif

Mathieu Faverge's avatar
Mathieu Faverge committed
360 361 362
/*******************************************************************************
 *  Get data addr
 **/
363
void *RUNTIME_desc_getaddr( const MORSE_desc_t *desc, int m, int n )
Mathieu Faverge's avatar
Mathieu Faverge committed
364 365 366 367
{
    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 );
}