runtime_descriptor.c 9.06 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 13
#include <parsec/data.h>
#include <parsec/datatype.h>
14
#include <parsec/data_dist/matrix/matrix.h>
Mathieu Faverge's avatar
Mathieu Faverge committed
15 16 17
#include <parsec/arena.h>

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

19 20 21 22 23
void RUNTIME_user_tag_size(int user_tag_width, int user_tag_sep) {
  (void)user_tag_width;
  (void)user_tag_sep;
}

24 25 26 27 28 29 30 31 32 33 34 35
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
36
struct morse_parsec_desc_s {
Mathieu Faverge's avatar
Mathieu Faverge committed
37
    parsec_data_collection_t  super;
Mathieu Faverge's avatar
Mathieu Faverge committed
38
    MORSE_desc_t  *desc;
Mathieu Faverge's avatar
Mathieu Faverge committed
39 40
    parsec_data_t **data_map;
    int arena_index;
Mathieu Faverge's avatar
Mathieu Faverge committed
41 42
};

43 44 45 46
int morse_parsec_get_arena_index(const MORSE_desc_t *desc) {
    return ((morse_parsec_desc_t *)desc->schedopt)->arena_index;
}

Mathieu Faverge's avatar
Mathieu Faverge committed
47
static void
Mathieu Faverge's avatar
Mathieu Faverge committed
48
morse_parsec_key_to_coordinates(parsec_data_collection_t *data_collection, parsec_data_key_t key,
Mathieu Faverge's avatar
Mathieu Faverge committed
49 50
                                int *m, int *n)
{
Mathieu Faverge's avatar
Mathieu Faverge committed
51
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
52 53 54 55 56 57 58 59 60
    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
61 62
static parsec_data_key_t
morse_parsec_data_key(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
63
{
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
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
Mathieu Faverge's avatar
Mathieu Faverge committed
70
    va_start(ap, data_collection);
Mathieu Faverge's avatar
Mathieu Faverge committed
71 72 73 74 75 76 77 78 79 80 81 82
    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
Mathieu Faverge's avatar
Mathieu Faverge committed
83
morse_parsec_rank_of(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
84
{
Mathieu Faverge's avatar
Mathieu Faverge committed
85
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
86 87 88 89 90
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
Mathieu Faverge's avatar
Mathieu Faverge committed
91
    va_start(ap, data_collection);
Mathieu Faverge's avatar
Mathieu Faverge committed
92 93 94 95 96 97 98 99 100 101 102 103
    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
Mathieu Faverge's avatar
Mathieu Faverge committed
104
morse_parsec_rank_of_key(parsec_data_collection_t *data_collection, parsec_data_key_t key)
Mathieu Faverge's avatar
Mathieu Faverge committed
105 106
{
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
107 108
    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
109 110 111
}

static int32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
112
morse_parsec_vpid_of(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
113 114 115 116 117
{
    return 0;
}

static int32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
118
morse_parsec_vpid_of_key(parsec_data_collection_t *data_collection, parsec_data_key_t key)
Mathieu Faverge's avatar
Mathieu Faverge committed
119 120
{
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
121 122
    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
123 124
}

Mathieu Faverge's avatar
Mathieu Faverge committed
125 126
static parsec_data_t*
morse_parsec_data_of(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
127
{
Mathieu Faverge's avatar
Mathieu Faverge committed
128
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
129 130 131 132 133
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
Mathieu Faverge's avatar
Mathieu Faverge committed
134
    va_start(ap, data_collection);
Mathieu Faverge's avatar
Mathieu Faverge committed
135 136 137 138 139 140 141 142 143 144
    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
145
    //assert( data_collection->nodes == 1 );
Mathieu Faverge's avatar
Mathieu Faverge committed
146
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
147 148
    return parsec_data_create( pdesc->data_map + n * mdesc->lmt + m, data_collection,
                              morse_parsec_data_key( data_collection, m, n ),
Mathieu Faverge's avatar
Mathieu Faverge committed
149 150
                              mdesc->get_blkaddr( mdesc, m, n ),
                              mdesc->bsiz * MORSE_Element_Size(mdesc->dtyp) );
Mathieu Faverge's avatar
Mathieu Faverge committed
151 152
}

Mathieu Faverge's avatar
Mathieu Faverge committed
153 154
static parsec_data_t*
morse_parsec_data_of_key(parsec_data_collection_t *data_collection, parsec_data_key_t key)
Mathieu Faverge's avatar
Mathieu Faverge committed
155
{
Mathieu Faverge's avatar
Mathieu Faverge committed
156
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
157 158
    MORSE_desc_t *mdesc = pdesc->desc;
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
159
    morse_parsec_key_to_coordinates(data_collection, key, &m, &n);
Mathieu Faverge's avatar
Mathieu Faverge committed
160 161 162

#if defined(CHAMELEON_USE_MPI)
    /* TODO: change displacement in data_map when in distributed */
Mathieu Faverge's avatar
Mathieu Faverge committed
163
    //assert( data_collection->nodes == 1 );
Mathieu Faverge's avatar
Mathieu Faverge committed
164
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
165
    return parsec_data_create( pdesc->data_map + key, data_collection, key,
Mathieu Faverge's avatar
Mathieu Faverge committed
166 167
                              mdesc->get_blkaddr( mdesc, m, n ),
                              mdesc->bsiz * MORSE_Element_Size(mdesc->dtyp) );
Mathieu Faverge's avatar
Mathieu Faverge committed
168 169
}

Mathieu Faverge's avatar
Mathieu Faverge committed
170
#ifdef parsec_PROF_TRACE
Mathieu Faverge's avatar
Mathieu Faverge committed
171
static int
Mathieu Faverge's avatar
Mathieu Faverge committed
172
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
173
{
Mathieu Faverge's avatar
Mathieu Faverge committed
174
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
175 176
    MORSE_desc_t *mdesc = pdesc->desc;
    int m, n, res;
Mathieu Faverge's avatar
Mathieu Faverge committed
177
    morse_parsec_key_to_coordinates(data_collection, key, &m, &n);
Mathieu Faverge's avatar
Mathieu Faverge committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    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 )
{
Mathieu Faverge's avatar
Mathieu Faverge committed
195
    parsec_data_collection_t       *data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
196 197 198 199
    morse_parsec_desc_t *pdesc;
    int comm_size;

    pdesc = malloc( sizeof(morse_parsec_desc_t) );
Mathieu Faverge's avatar
Mathieu Faverge committed
200
    data_collection = (parsec_data_collection_t*)pdesc;
Mathieu Faverge's avatar
Mathieu Faverge committed
201 202 203

    /* Super setup */
    RUNTIME_comm_size( &comm_size );
Mathieu Faverge's avatar
Mathieu Faverge committed
204 205 206 207 208 209 210 211 212 213 214
    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
215 216
    {
        int rc;
Mathieu Faverge's avatar
Mathieu Faverge committed
217 218 219
        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
220 221 222
        (void)rc;
    }
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
223
    data_collection->memory_registration_status = MEMORY_STATUS_UNREGISTERED;
Mathieu Faverge's avatar
Mathieu Faverge committed
224

Mathieu Faverge's avatar
Mathieu Faverge committed
225
    pdesc->data_map = calloc( mdesc->lmt * mdesc->lnt, sizeof(parsec_data_t*) );
Mathieu Faverge's avatar
Mathieu Faverge committed
226 227 228 229 230

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

Mathieu Faverge's avatar
Mathieu Faverge committed
231 232
    parsec_dtd_data_collection_init(data_collection);

233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
    /* 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) {
        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;
    }

    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
253 254 255 256 257 258 259 260 261 262 263
    /* /\* 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 ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
264
        parsec_data_t **data = pdesc->data_map;
Mathieu Faverge's avatar
Mathieu Faverge committed
265 266 267 268 269
        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
270
            parsec_data_destroy( *data );
Mathieu Faverge's avatar
Mathieu Faverge committed
271 272 273 274 275
        }

        free( pdesc->data_map );
        pdesc->data_map = NULL;
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
276 277 278

    parsec_dtd_data_collection_fini( (parsec_data_collection_t *)pdesc );

Mathieu Faverge's avatar
Mathieu Faverge committed
279
    free(pdesc);
Mathieu Faverge's avatar
Mathieu Faverge committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
    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;
}

307
void *RUNTIME_desc_getaddr( const MORSE_desc_t *desc, int m, int n )
Mathieu Faverge's avatar
Mathieu Faverge committed
308 309 310 311
{
    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 );
}