zbuild.c 9.94 KB
Newer Older
1
/**
2 3
 *
 * @file zbuild.c
4
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
5 6
 * @copyright 2009-2014 The University of Tennessee and The University of
 *                      Tennessee Research Foundation. All rights reserved.
Mathieu Faverge's avatar
Mathieu Faverge committed
7
 * @copyright 2012-2018 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8
 *                      Univ. Bordeaux. All rights reserved.
9
 *
10
 * @brief Chameleon zbuild wrappers
11
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
12
 * @version 1.0.0
13
 * @comment This file has been automatically generated
14
 *          from Plasma 2.5.0 for CHAMELEON 1.0.0
15 16 17 18 19 20 21
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @author Guillaume Sylvand
 * @date 2016-09-05
 * @precisions normal z -> s d c
 *
22
 */
23 24
#include "control/common.h"

25 26
/**
 ********************************************************************************
27
 *
28
 * @ingroup CHAMELEON_Complex64_t
29
 *
30
 *  CHAMELEON_zbuild - Generate a matrix by calling user provided function.
31 32 33 34 35
 *
 *******************************************************************************
 *
 * @param[in] uplo
 *          Specifies the part of the matrix A to be copied to B.
36 37 38
 *            = ChamUpperLower: All the matrix A
 *            = ChamUpper: Upper triangular part
 *            = ChamLower: Lower triangular part
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
 *
 * @param[in] M
 *          The number of rows of A.
 *
 * @param[in] N
 *          The order of the matrix A. N >= 0.
 *
 * @param[out] A
 *          On exit, The matrix A generated.
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,M).
 *
 * @param[in] user_data
 *          The user data used in the matrix generation, it will be passed by chameleon
 *          to the build callback function (see below).
 *
 * @param[in] user_build_callback
 *          The user function to call to generate tiles.
 *          The prototype of the callback is :
 *          void myFcn(int row_min, int row_max, int col_min, int col_max, void *buffer, int ld, void *user_data)
 *          It is expected to build the block of matrix [row_min, row_max] x [col_min, col_max]
 *          (with both min and max values included in the intervals,
 *          index start at 0 like in C, NOT 1 like in Fortran)
 *          and store it at the adresse 'buffer' with leading dimension 'ld'
 *          The argument 'user_data' is an opaque pointer on any user data, it is passed by
65
 *          the user to Cham_zbuild (see above) and transmitted by chameleon to the callback.
66 67 68
 *
 *******************************************************************************
 *
69 70
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
71 72 73
 *
 *******************************************************************************
 *
74 75 76 77 78
 * @sa CHAMELEON_zbuild_Tile
 * @sa CHAMELEON_zbuild_Tile_Async
 * @sa CHAMELEON_cbuild
 * @sa CHAMELEON_dbuild
 * @sa CHAMELEON_sbuild
79
 *
80
 */
81 82
int CHAMELEON_zbuild( cham_uplo_t uplo, int M, int N,
                  CHAMELEON_Complex64_t *A, int LDA,
Mathieu Faverge's avatar
Mathieu Faverge committed
83
                  void *user_data, void* user_build_callback )
84
{
Mathieu Faverge's avatar
Mathieu Faverge committed
85 86
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
87
    CHAM_context_t *chamctxt;
88 89 90
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
91

Mathieu Faverge's avatar
Mathieu Faverge committed
92 93 94
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zbuild", "CHAMELEON not initialized");
95
        return CHAMELEON_ERR_NOT_INITIALIZED;
Mathieu Faverge's avatar
Mathieu Faverge committed
96 97 98
    }
    /* Check input arguments */
    if (M < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
99
        chameleon_error("CHAMELEON_zbuild", "illegal value of M");
Mathieu Faverge's avatar
Mathieu Faverge committed
100 101 102
        return -1;
    }
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
103
        chameleon_error("CHAMELEON_zbuild", "illegal value of N");
Mathieu Faverge's avatar
Mathieu Faverge committed
104 105 106
        return -2;
    }
    if (LDA < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
107
        chameleon_error("CHAMELEON_zbuild", "illegal value of LDA");
Mathieu Faverge's avatar
Mathieu Faverge committed
108 109 110 111
        return -4;
    }
    /* Quick return */
    if (chameleon_min(M, N) == 0)
112
        return CHAMELEON_SUCCESS;
113

Mathieu Faverge's avatar
Mathieu Faverge committed
114
    /* Tune NB depending on M, N & NRHS; Set NBNB */
Mathieu Faverge's avatar
Mathieu Faverge committed
115
    status = chameleon_tune(CHAMELEON_FUNC_ZGEMM, M, N, 0);
116
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
117
        chameleon_error("CHAMELEON_zbuild", "chameleon_tune() failed");
Mathieu Faverge's avatar
Mathieu Faverge committed
118 119
        return status;
    }
120

Mathieu Faverge's avatar
Mathieu Faverge committed
121
    /* Set NT */
122
    NB = CHAMELEON_NB;
Mathieu Faverge's avatar
Mathieu Faverge committed
123
    chameleon_sequence_create( chamctxt, &sequence );
124 125

    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
126
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescOutput, uplo,
127
                     A, NB, NB, LDA, N, M, N, sequence, &request );
128

Mathieu Faverge's avatar
Mathieu Faverge committed
129
    /* Call the tile interface */
130
    CHAMELEON_zbuild_Tile_Async( uplo, &descAt, user_data, user_build_callback, sequence, &request );
131

Mathieu Faverge's avatar
Mathieu Faverge committed
132
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
133
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
134
                     ChamDescOutput, uplo, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
135

Mathieu Faverge's avatar
Mathieu Faverge committed
136
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
137

Mathieu Faverge's avatar
Mathieu Faverge committed
138
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
139
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
140

Mathieu Faverge's avatar
Mathieu Faverge committed
141
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
142
    chameleon_sequence_destroy( chamctxt, sequence );
143

Mathieu Faverge's avatar
Mathieu Faverge committed
144
    return status;
145 146
}

147 148
/**
 ********************************************************************************
149
 *
150
 * @ingroup CHAMELEON_Complex64_t_Tile
151
 *
152 153
 *  CHAMELEON_zbuild_Tile - Generate a matrix by tiles by calling user provided function.
 *  Tile equivalent of CHAMELEON_zbuild().
154 155 156 157 158 159 160 161
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] uplo
 *          Specifies the part of the matrix A to be copied to B.
162 163 164
 *            = ChamUpperLower: All the matrix A
 *            = ChamUpper: Upper triangular part
 *            = ChamLower: Lower triangular part
165 166 167 168 169 170 171 172
 *
 * @param[in] A
 *          On exit, The matrix A generated.
 *
 * @param[in] user_data
 *          The data used in the matrix generation.
 *
 * @param[in] user_build_callback
173
 *          The function called by the codelet to fill the tiles (see CHAMELEON_zbuild)
174 175 176
 *
 *******************************************************************************
 *
177
 * @retval CHAMELEON_SUCCESS successful exit
178 179 180
 *
 *******************************************************************************
 *
181 182 183 184 185
 * @sa CHAMELEON_zbuild
 * @sa CHAMELEON_zbuild_Tile_Async
 * @sa CHAMELEON_cbuild_Tile
 * @sa CHAMELEON_dbuild_Tile
 * @sa CHAMELEON_sbuild_Tile
186
 *
187
 */
188
int CHAMELEON_zbuild_Tile( cham_uplo_t uplo, CHAM_desc_t *A,
189 190
                       void *user_data, void* user_build_callback )
{
Mathieu Faverge's avatar
Mathieu Faverge committed
191
    CHAM_context_t *chamctxt;
192 193
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
Mathieu Faverge's avatar
Mathieu Faverge committed
194
    int status;
195

Mathieu Faverge's avatar
Mathieu Faverge committed
196 197 198
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zbuild_Tile", "CHAMELEON not initialized");
199
        return CHAMELEON_ERR_NOT_INITIALIZED;
Mathieu Faverge's avatar
Mathieu Faverge committed
200
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
201
    chameleon_sequence_create( chamctxt, &sequence );
202

203
    CHAMELEON_zbuild_Tile_Async( uplo, A, user_data, user_build_callback, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
204

205
    CHAMELEON_Desc_Flush( A, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
206

Mathieu Faverge's avatar
Mathieu Faverge committed
207
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
208
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
209
    chameleon_sequence_destroy( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
210
    return status;
211 212
}

213 214
/**
 ********************************************************************************
215
 *
216
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
217
 *
218 219
 *  CHAMELEON_zbuild_Tile_Async - Generate a matrix by tiles by calling user provided function.
 *  Non-blocking equivalent of CHAMELEON_zbuild_Tile().
220 221 222 223 224 225 226
 *  May return before the computation is finished.
 *  Allows for pipelining of operations at runtime.
 *
 *******************************************************************************
 *
 * @param[in] uplo
 *          Specifies the part of the matrix A to be copied to B.
227 228 229
 *            = ChamUpperLower: All the matrix A
 *            = ChamUpper: Upper triangular part
 *            = ChamLower: Lower triangular part
230 231 232 233 234 235 236 237
 *
 * @param[in] A
 *          On exit, The matrix A generated.
 *
 * @param[in] user_data
 *          The data used in the matrix generation.
 *
 * @param[in] user_build_callback
238
 *          The function called by the codelet to fill the tiles (see CHAMELEON_zbuild)
239 240 241 242 243 244 245 246 247 248
 *
 * @param[in] sequence
 *          Identifies the sequence of function calls that this call belongs to
 *          (for completion checks and exception handling purposes).
 *
 * @param[out] request
 *          Identifies this function call (for exception handling purposes).
 *
 *******************************************************************************
 *
249 250 251 252 253
 * @sa CHAMELEON_zbuild
 * @sa CHAMELEON_zbuild_Tile
 * @sa CHAMELEON_cbuild_Tile_Async
 * @sa CHAMELEON_dbuild_Tile_Async
 * @sa CHAMELEON_sbuild_Tile_Async
254
 *
255
 */
256
int CHAMELEON_zbuild_Tile_Async( cham_uplo_t uplo, CHAM_desc_t     *A,
257
                             void *user_data, void* user_build_callback,
258 259
                             RUNTIME_sequence_t *sequence,
                             RUNTIME_request_t  *request )
260
{
Mathieu Faverge's avatar
Mathieu Faverge committed
261
    CHAM_context_t *chamctxt;
262

Mathieu Faverge's avatar
Mathieu Faverge committed
263 264 265
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zbuild_Tile", "CHAMELEON not initialized");
266
        return CHAMELEON_ERR_NOT_INITIALIZED;
Mathieu Faverge's avatar
Mathieu Faverge committed
267 268
    }
    if (sequence == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
269
        chameleon_fatal_error("CHAMELEON_zbuild_Tile", "NULL sequence");
270
        return CHAMELEON_ERR_UNALLOCATED;
Mathieu Faverge's avatar
Mathieu Faverge committed
271 272
    }
    if (request == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
273
        chameleon_fatal_error("CHAMELEON_zbuild_Tile", "NULL request");
274
        return CHAMELEON_ERR_UNALLOCATED;
Mathieu Faverge's avatar
Mathieu Faverge committed
275 276
    }
    /* Check sequence status */
277 278
    if (sequence->status == CHAMELEON_SUCCESS) {
        request->status = CHAMELEON_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
279 280
    }
    else {
Mathieu Faverge's avatar
Mathieu Faverge committed
281
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_SEQUENCE_FLUSHED);
Mathieu Faverge's avatar
Mathieu Faverge committed
282
    }
283

Mathieu Faverge's avatar
Mathieu Faverge committed
284
    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
285 286 287
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zbuild_Tile", "invalid descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
Mathieu Faverge's avatar
Mathieu Faverge committed
288
    }
289

Mathieu Faverge's avatar
Mathieu Faverge committed
290
    /* Quick return */
Mathieu Faverge's avatar
Mathieu Faverge committed
291
    if (chameleon_min( A->m, A->n ) == 0) {
292
        return CHAMELEON_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
293
    }
294

Mathieu Faverge's avatar
Mathieu Faverge committed
295
    chameleon_pzbuild( uplo, A, user_data, user_build_callback, sequence, request );
296

297
    return CHAMELEON_SUCCESS;
298
}