runtime_descriptor.c 8.2 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 14 15 16
#include <parsec/data.h>
#include <parsec/datatype.h>
#include <parsec/arena.h>

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

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

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

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

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

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

static int32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
107
morse_parsec_vpid_of(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
108 109 110 111 112
{
    return 0;
}

static int32_t
Mathieu Faverge's avatar
Mathieu Faverge committed
113
morse_parsec_vpid_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_vpid_of(data_collection, m, n);
Mathieu Faverge's avatar
Mathieu Faverge committed
118 119
}

Mathieu Faverge's avatar
Mathieu Faverge committed
120 121
static parsec_data_t*
morse_parsec_data_of(parsec_data_collection_t *data_collection, ...)
Mathieu Faverge's avatar
Mathieu Faverge committed
122
{
Mathieu Faverge's avatar
Mathieu Faverge committed
123
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
124 125 126 127 128
    MORSE_desc_t *mdesc = pdesc->desc;
    va_list ap;
    int m, n;

    /* Get coordinates */
Mathieu Faverge's avatar
Mathieu Faverge committed
129
    va_start(ap, data_collection);
Mathieu Faverge's avatar
Mathieu Faverge committed
130 131 132 133 134 135 136 137 138 139
    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
140
    //assert( data_collection->nodes == 1 );
Mathieu Faverge's avatar
Mathieu Faverge committed
141
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
142 143
    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
144 145
                              mdesc->get_blkaddr( mdesc, m, n ),
                              mdesc->bsiz * MORSE_Element_Size(mdesc->dtyp) );
Mathieu Faverge's avatar
Mathieu Faverge committed
146 147
}

Mathieu Faverge's avatar
Mathieu Faverge committed
148 149
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
150
{
Mathieu Faverge's avatar
Mathieu Faverge committed
151
    morse_parsec_desc_t *pdesc = (morse_parsec_desc_t*)data_collection;
Mathieu Faverge's avatar
Mathieu Faverge committed
152 153
    MORSE_desc_t *mdesc = pdesc->desc;
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
154
    morse_parsec_key_to_coordinates(data_collection, key, &m, &n);
Mathieu Faverge's avatar
Mathieu Faverge committed
155 156 157

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

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

    pdesc = malloc( sizeof(morse_parsec_desc_t) );
Mathieu Faverge's avatar
Mathieu Faverge committed
195
    data_collection = (parsec_data_collection_t*)pdesc;
Mathieu Faverge's avatar
Mathieu Faverge committed
196 197 198

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

Mathieu Faverge's avatar
Mathieu Faverge committed
220
    pdesc->data_map = calloc( mdesc->lmt * mdesc->lnt, sizeof(parsec_data_t*) );
Mathieu Faverge's avatar
Mathieu Faverge committed
221 222 223 224 225

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

Mathieu Faverge's avatar
Mathieu Faverge committed
226 227
    parsec_dtd_data_collection_init(data_collection);

Reazul Hoque's avatar
Reazul Hoque committed
228 229 230 231
    /*dplasma_add2arena_tile( parsec_dtd_arenas[0],
                            mdesc->mb*mdesc->nb*sizeof(MORSE_Complex64_t),
                            PARSEC_ARENA_ALIGNMENT_SSE,
                            parsec_datatype_double_complex_t, mdesc->mb ); */
Mathieu Faverge's avatar
Mathieu Faverge committed
232 233 234 235 236 237 238 239 240 241 242
    /* /\* 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
243
        parsec_data_t **data = pdesc->data_map;
Mathieu Faverge's avatar
Mathieu Faverge committed
244 245 246 247 248
        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
249
            parsec_data_destroy( *data );
Mathieu Faverge's avatar
Mathieu Faverge committed
250 251 252 253 254
        }

        free( pdesc->data_map );
        pdesc->data_map = NULL;
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
255 256 257

    parsec_dtd_data_collection_fini( (parsec_data_collection_t *)pdesc );

Mathieu Faverge's avatar
Mathieu Faverge committed
258
    free(pdesc);
Mathieu Faverge's avatar
Mathieu Faverge committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
    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;
}

286
void *RUNTIME_desc_getaddr( const MORSE_desc_t *desc, int m, int n )
Mathieu Faverge's avatar
Mathieu Faverge committed
287 288 289 290
{
    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 );
}