runtime_descriptor.c 10.2 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
Mathieu Faverge's avatar
Mathieu Faverge committed
121
morse_parsec_vpid_of(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
122 123 124 125
{
    return 0;
}

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

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

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

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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
179
#ifdef parsec_PROF_TRACE
Mathieu Faverge's avatar
Mathieu Faverge committed
180
static inline int
Mathieu Faverge's avatar
Mathieu Faverge committed
181
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
182
{
Mathieu Faverge's avatar
Mathieu Faverge committed
183
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
184 185
    MORSE_desc_t *mdesc = pdesc->desc;
    int m, n, res;
Mathieu Faverge's avatar
Mathieu Faverge committed
186
    morse_parsec_key_to_coordinates(data_collection, key, &m, &n);
Mathieu Faverge's avatar
Mathieu Faverge committed
187 188 189 190 191 192 193 194 195
    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
196 197 198
/*******************************************************************************
 *  Create data descriptor
 **/
Mathieu Faverge's avatar
Mathieu Faverge committed
199 200
void RUNTIME_desc_create( MORSE_desc_t *mdesc )
{
Mathieu Faverge's avatar
Mathieu Faverge committed
201
    parsec_data_collection_t *data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
202 203 204 205
    morse_parsec_desc_t *pdesc;
    int comm_size;

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

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

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

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

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

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

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

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

        free( pdesc->data_map );
        pdesc->data_map = NULL;
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
285 286 287

    parsec_dtd_data_collection_fini( (parsec_data_collection_t *)pdesc );

Mathieu Faverge's avatar
Mathieu Faverge committed
288
    free(pdesc);
Mathieu Faverge's avatar
Mathieu Faverge committed
289 290 291
    return;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
292 293 294 295
/*******************************************************************************
 *  Acquire data
 **/
int RUNTIME_desc_acquire( const MORSE_desc_t *desc )
Mathieu Faverge's avatar
Mathieu Faverge committed
296 297
{
    (void)desc;
Mathieu Faverge's avatar
Mathieu Faverge committed
298
    return MORSE_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
299 300
}

Mathieu Faverge's avatar
Mathieu Faverge committed
301 302 303 304
/*******************************************************************************
 *  Release data
 **/
int RUNTIME_desc_release( const MORSE_desc_t *desc )
Mathieu Faverge's avatar
Mathieu Faverge committed
305 306 307 308 309
{
    (void)desc;
    return MORSE_SUCCESS;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
310
/*******************************************************************************
Mathieu Faverge's avatar
Mathieu Faverge committed
311
 *  Flush cached data
Mathieu Faverge's avatar
Mathieu Faverge committed
312
 **/
Mathieu Faverge's avatar
Mathieu Faverge committed
313
void RUNTIME_flush()
Mathieu Faverge's avatar
Mathieu Faverge committed
314 315 316
{
}

Mathieu Faverge's avatar
Mathieu Faverge committed
317 318
void RUNTIME_desc_flush( const MORSE_desc_t     *desc,
                         const MORSE_sequence_t *sequence )
Mathieu Faverge's avatar
Mathieu Faverge committed
319
{
Mathieu Faverge's avatar
Mathieu Faverge committed
320 321 322
    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
323
}
Mathieu Faverge's avatar
Mathieu Faverge committed
324

Mathieu Faverge's avatar
Mathieu Faverge committed
325 326 327 328 329 330
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
331 332
}

Mathieu Faverge's avatar
Mathieu Faverge committed
333 334 335
/*******************************************************************************
 *  Get data addr
 **/
336
void *RUNTIME_desc_getaddr( const MORSE_desc_t *desc, int m, int n )
Mathieu Faverge's avatar
Mathieu Faverge committed
337 338 339 340
{
    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 );
}