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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
25 26 27 28 29
void RUNTIME_comm_set_tag_sizes( int user_tag_width,
                                 int user_tag_sep )
{
    (void)user_tag_width;
    (void)user_tag_sep;
30 31
}

Mathieu Faverge's avatar
Mathieu Faverge committed
32
void *RUNTIME_malloc( size_t size )
33 34 35 36
{
    return malloc(size);
}

Mathieu Faverge's avatar
Mathieu Faverge committed
37
void RUNTIME_free( void *ptr, size_t size )
38 39
{
    (void)size;
Mathieu Faverge's avatar
Mathieu Faverge committed
40
    free(ptr);
41 42 43
    return;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
44
struct morse_parsec_desc_s {
Mathieu Faverge's avatar
Mathieu Faverge committed
45
    parsec_data_collection_t  super;
Mathieu Faverge's avatar
Mathieu Faverge committed
46
    MORSE_desc_t  *desc;
Mathieu Faverge's avatar
Mathieu Faverge committed
47 48
    parsec_data_t **data_map;
    int arena_index;
Mathieu Faverge's avatar
Mathieu Faverge committed
49 50
};

Mathieu Faverge's avatar
Mathieu Faverge committed
51 52
int
morse_parsec_get_arena_index(const MORSE_desc_t *desc) {
53 54 55
    return ((morse_parsec_desc_t *)desc->schedopt)->arena_index;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
56
static inline void
Mathieu Faverge's avatar
Mathieu Faverge committed
57
morse_parsec_key_to_coordinates(parsec_data_collection_t *data_collection, parsec_data_key_t key,
Mathieu Faverge's avatar
Mathieu Faverge committed
58 59
                                int *m, int *n)
{
Mathieu Faverge's avatar
Mathieu Faverge committed
60
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
61 62 63 64 65 66 67 68 69
    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
70
static inline parsec_data_key_t
Mathieu Faverge's avatar
Mathieu Faverge committed
71
morse_parsec_data_key(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
72
{
Mathieu Faverge's avatar
Mathieu Faverge committed
73
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
74 75 76 77 78
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
Mathieu Faverge's avatar
Mathieu Faverge committed
79
    va_start(ap, data_collection);
Mathieu Faverge's avatar
Mathieu Faverge committed
80 81 82 83 84 85 86 87 88 89 90
    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
91
static inline uint32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
92
morse_parsec_rank_of(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
93
{
Mathieu Faverge's avatar
Mathieu Faverge committed
94
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
95 96 97 98 99
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
Mathieu Faverge's avatar
Mathieu Faverge committed
100
    va_start(ap, data_collection);
Mathieu Faverge's avatar
Mathieu Faverge committed
101 102 103 104 105 106 107 108 109 110 111
    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
112
static inline uint32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
113
morse_parsec_rank_of_key(parsec_data_collection_t *data_collection, parsec_data_key_t key)
Mathieu Faverge's avatar
Mathieu Faverge committed
114 115
{
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
116 117
    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
118 119
}

Mathieu Faverge's avatar
Mathieu Faverge committed
120
static inline int32_t
121
morse_parsec_vpid_of(parsec_data_collection_t *data_collection, ... )
Mathieu Faverge's avatar
Mathieu Faverge committed
122
{
123
    (void)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
124 125 126
    return 0;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
127
static inline int32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
128
morse_parsec_vpid_of_key(parsec_data_collection_t *data_collection, parsec_data_key_t key)
Mathieu Faverge's avatar
Mathieu Faverge committed
129 130
{
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
131 132
    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
133 134
}

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

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

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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
180
#ifdef parsec_PROF_TRACE
Mathieu Faverge's avatar
Mathieu Faverge committed
181
static inline int
Mathieu Faverge's avatar
Mathieu Faverge committed
182
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
183
{
Mathieu Faverge's avatar
Mathieu Faverge committed
184
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
185 186
    MORSE_desc_t *mdesc = pdesc->desc;
    int m, n, res;
Mathieu Faverge's avatar
Mathieu Faverge committed
187
    morse_parsec_key_to_coordinates(data_collection, key, &m, &n);
Mathieu Faverge's avatar
Mathieu Faverge committed
188 189 190 191 192 193 194 195 196
    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

Mathieu Faverge's avatar
Mathieu Faverge committed
197 198 199
/*******************************************************************************
 *  Create data descriptor
 **/
Mathieu Faverge's avatar
Mathieu Faverge committed
200 201
void RUNTIME_desc_create( MORSE_desc_t *mdesc )
{
Mathieu Faverge's avatar
Mathieu Faverge committed
202
    parsec_data_collection_t *data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
203 204 205 206
    morse_parsec_desc_t *pdesc;
    int comm_size;

    pdesc = malloc( sizeof(morse_parsec_desc_t) );
Mathieu Faverge's avatar
Mathieu Faverge committed
207
    data_collection = (parsec_data_collection_t*)pdesc;
Mathieu Faverge's avatar
Mathieu Faverge committed
208 209

    /* Super setup */
Mathieu Faverge's avatar
Mathieu Faverge committed
210
    comm_size = RUNTIME_comm_size( NULL );
Mathieu Faverge's avatar
Mathieu Faverge committed
211 212 213 214 215 216 217 218 219 220 221
    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
222 223
    {
        int rc;
Mathieu Faverge's avatar
Mathieu Faverge committed
224 225 226
        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
227 228 229
        (void)rc;
    }
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
230
    data_collection->memory_registration_status = MEMORY_STATUS_UNREGISTERED;
Mathieu Faverge's avatar
Mathieu Faverge committed
231

Mathieu Faverge's avatar
Mathieu Faverge committed
232
    pdesc->data_map = calloc( mdesc->lmt * mdesc->lnt, sizeof(parsec_data_t*) );
Mathieu Faverge's avatar
Mathieu Faverge committed
233 234 235 236 237

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

Mathieu Faverge's avatar
Mathieu Faverge committed
238 239
    parsec_dtd_data_collection_init(data_collection);

240 241 242 243 244 245 246 247 248 249
    /* arena init */
    /* 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
250 251 252 253 254 255
    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;
256 257 258 259
    }

    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
260 261 262 263 264 265
    /* /\* 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
266 267 268
/*******************************************************************************
 *  Destroy data descriptor
 **/
Mathieu Faverge's avatar
Mathieu Faverge committed
269 270 271
void RUNTIME_desc_destroy( MORSE_desc_t *mdesc )
{
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)(mdesc->schedopt);
272 273 274
    if ( pdesc == NULL ) {
        return;
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
275 276

    if ( pdesc->data_map != NULL ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
277
        parsec_data_t **data = pdesc->data_map;
Mathieu Faverge's avatar
Mathieu Faverge committed
278 279 280 281 282
        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
283
            parsec_data_destroy( *data );
Mathieu Faverge's avatar
Mathieu Faverge committed
284 285 286 287 288
        }

        free( pdesc->data_map );
        pdesc->data_map = NULL;
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
289 290 291

    parsec_dtd_data_collection_fini( (parsec_data_collection_t *)pdesc );

Mathieu Faverge's avatar
Mathieu Faverge committed
292
    free(pdesc);
293
    mdesc->schedopt = NULL;
Mathieu Faverge's avatar
Mathieu Faverge committed
294 295 296
    return;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
297 298 299 300
/*******************************************************************************
 *  Acquire data
 **/
int RUNTIME_desc_acquire( const MORSE_desc_t *desc )
Mathieu Faverge's avatar
Mathieu Faverge committed
301 302
{
    (void)desc;
Mathieu Faverge's avatar
Mathieu Faverge committed
303
    return MORSE_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
304 305
}

Mathieu Faverge's avatar
Mathieu Faverge committed
306 307 308 309
/*******************************************************************************
 *  Release data
 **/
int RUNTIME_desc_release( const MORSE_desc_t *desc )
Mathieu Faverge's avatar
Mathieu Faverge committed
310 311 312 313 314
{
    (void)desc;
    return MORSE_SUCCESS;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
315
/*******************************************************************************
Mathieu Faverge's avatar
Mathieu Faverge committed
316
 *  Flush cached data
Mathieu Faverge's avatar
Mathieu Faverge committed
317
 **/
Mathieu Faverge's avatar
Mathieu Faverge committed
318
void RUNTIME_flush()
Mathieu Faverge's avatar
Mathieu Faverge committed
319 320 321
{
}

Mathieu Faverge's avatar
Mathieu Faverge committed
322 323
void RUNTIME_desc_flush( const MORSE_desc_t     *desc,
                         const MORSE_sequence_t *sequence )
Mathieu Faverge's avatar
Mathieu Faverge committed
324
{
Mathieu Faverge's avatar
Mathieu Faverge committed
325 326 327
    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
328
}
Mathieu Faverge's avatar
Mathieu Faverge committed
329

Mathieu Faverge's avatar
Mathieu Faverge committed
330 331 332 333 334 335
void RUNTIME_data_flush( const MORSE_sequence_t *sequence,
                         const MORSE_desc_t *A, int Am, int An )
{
    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 ) );
Mathieu Faverge's avatar
Mathieu Faverge committed
336 337
}

Mathieu Faverge's avatar
Mathieu Faverge committed
338 339 340
/*******************************************************************************
 *  Get data addr
 **/
341
void *RUNTIME_desc_getaddr( const MORSE_desc_t *desc, int m, int n )
Mathieu Faverge's avatar
Mathieu Faverge committed
342 343 344 345
{
    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 );
}