chameleon_starpu.h.in 5.66 KB
Newer Older
1
/**
2
 *
3
 * @file starpu/chameleon_starpu.h
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
 ***
11
 *
12
 * @brief Chameleon StarPU runtime header
13
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 * @version 1.0.0
15 16
 * @author Mathieu Faverge
 * @author Cedric Castagnede
17
 * @author Florent Pruvost
18 19
 * @date 2011-06-01
 *
20
 */
21 22
#ifndef _chameleon_starpu_h_
#define _chameleon_starpu_h_
23

24
#include "chameleon/config.h"
PRUVOST Florent's avatar
PRUVOST Florent committed
25

26 27 28 29 30 31 32
/* StarPU options */
#cmakedefine HAVE_STARPU_FXT_PROFILING
#cmakedefine HAVE_STARPU_IDLE_PREFETCH
#cmakedefine HAVE_STARPU_ITERATION_PUSH
#cmakedefine HAVE_STARPU_DATA_WONT_USE
#cmakedefine HAVE_STARPU_DATA_SET_COORDINATES
#cmakedefine HAVE_STARPU_MALLOC_ON_NODE_SET_DEFAULT_FLAGS
THIBAULT Samuel's avatar
THIBAULT Samuel committed
33
#cmakedefine HAVE_STARPU_DATA_SET_OOC_FLAG
34
#cmakedefine HAVE_STARPU_MPI_DATA_MIGRATE
35 36 37
#cmakedefine HAVE_STARPU_MPI_DATA_REGISTER
#cmakedefine HAVE_STARPU_MPI_COMM_RANK
#cmakedefine HAVE_STARPU_MPI_CACHED_RECEIVE
Mathieu Faverge's avatar
Mathieu Faverge committed
38
#cmakedefine HAVE_STARPU_MPI_COMM_GET_ATTR
39

40
#if defined(CHAMELEON_USE_MPI)
41 42 43 44 45 46 47
#include <starpu_mpi.h>
#else
#include <starpu.h>
#endif

#include <starpu_profiling.h>

48
#if defined(CHAMELEON_USE_CUDA) && !defined(CHAMELEON_SIMULATION)
49 50
#include <starpu_scheduler.h>
#include <starpu_cuda.h>
51 52 53 54 55 56 57

#include <cublas.h>
#include <starpu_cublas.h>
#if defined(CHAMELEON_USE_CUBLAS_V2)
#include <cublas_v2.h>
#include <starpu_cublas_v2.h>
#endif
58 59
#endif

60 61 62 63 64 65 66 67 68 69
#if defined(CHAMELEON_SIMULATION)
# if !defined(STARPU_SIMGRID)
#  error "Starpu was not built with simgrid support (--enable-simgrid). Can not run Chameleon with simulation support."
# endif
#else
# if defined(STARPU_SIMGRID)
#  warning "Starpu was built with simgrid support. Better build Chameleon with simulation support (-DCHAMELEON_SIMULATION=YES)."
# endif
#endif

70
#include "control/common.h"
71 72 73 74
#include "runtime_codelets.h"
#include "runtime_profiling.h"
#include "runtime_codelet_profile.h"
#include "runtime_workspace.h"
75 76 77

typedef struct starpu_conf starpu_conf_t;

78
/**/
79 80 81 82

/*
 * MPI Redefinitions
 */
83
#if defined(CHAMELEON_USE_MPI)
84
#undef STARPU_REDUX
85 86 87 88 89 90 91 92
//#define starpu_insert_task(...) starpu_mpi_insert_task(MPI_COMM_WORLD, __VA_ARGS__)
#define starpu_insert_task starpu_mpi_insert_task
#define starpu_mpi_codelet(_codelet_) MPI_COMM_WORLD, _codelet_

#else

#define starpu_mpi_codelet(_codelet_) _codelet_

93 94
#endif

95 96 97 98 99 100 101 102 103 104 105 106 107
/*
 * cuBlasAPI v2 - StarPU enable the support for cublas handle
 */
#if defined(CHAMELEON_USE_CUDA) && defined(CHAMELEON_USE_CUBLAS_V2)
#define RUNTIME_getStream(_stream_)                             \
    cublasHandle_t _stream_ = starpu_cublas_get_local_handle();
#else
#define RUNTIME_getStream(_stream_)                             \
    cudaStream_t _stream_ = starpu_cuda_get_local_stream();     \
    cublasSetKernelStream( stream );

#endif

108
/*
109 110 111 112 113 114 115
 * Enable codelets names
 */
#if (STARPU_MAJOR_VERSION > 1) || ((STARPU_MAJOR_VERSION == 1) && (STARPU_MINOR_VERSION > 1))
#define CHAMELEON_CODELETS_HAVE_NAME
#endif

/**
116 117
 * Access to block pointer and leading dimension
 */
118
#define RTBLKADDR( desc, type, m, n ) ( (starpu_data_handle_t)RUNTIME_data_getaddr( desc, m, n ) )
119

120
void RUNTIME_set_reduction_methods(starpu_data_handle_t handle, cham_flttype_t dtyp);
121

122 123
#if defined(CHAMELEON_USE_MPI) && defined(HAVE_STARPU_MPI_CACHED_RECEIVE)
static inline int
124
chameleon_starpu_data_iscached(const CHAM_desc_t *A, int m, int n)
125
{
Mathieu Faverge's avatar
Mathieu Faverge committed
126 127 128 129 130
    int64_t mm = m + (A->i / A->mb);
    int64_t nn = n + (A->j / A->nb);

    starpu_data_handle_t *ptrtile = A->schedopt;
    ptrtile += ((int64_t)A->lmt) * nn + mm;
131

Mathieu Faverge's avatar
Mathieu Faverge committed
132
    if (!(*ptrtile)) {
133
        return 0;
Mathieu Faverge's avatar
Mathieu Faverge committed
134
    }
135 136 137 138 139

    return starpu_mpi_cached_receive(*ptrtile);
}

#define RUNTIME_ACCESS_WRITE_CACHED(A, Am, An) do {                 \
Mathieu Faverge's avatar
Mathieu Faverge committed
140
        if (chameleon_starpu_data_iscached(A, Am, An)) __chameleon_need_submit = 1; } while(0)
141

142
#else
143

Mathieu Faverge's avatar
Mathieu Faverge committed
144
#if defined(CHAMELEON_USE_MPI)
145
#warning "WAR dependencies need starpu_mpi_cached_receive support from StarPU 1.2.1 or greater"
Mathieu Faverge's avatar
Mathieu Faverge committed
146
#endif
147 148
#define RUNTIME_ACCESS_WRITE_CACHED(A, Am, An) do {} while (0)

149
#endif
150

151 152 153
#ifdef CHAMELEON_ENABLE_PRUNING_STATS

#define RUNTIME_PRUNING_STATS_BEGIN_ACCESS_DECLARATION \
Mathieu Faverge's avatar
Mathieu Faverge committed
154 155
    int __chameleon_exec = 0; \
    int __chameleon_changed = 0;
156 157

#define RUNTIME_PRUNING_STATS_ACCESS_W(A, Am, An) \
Mathieu Faverge's avatar
Mathieu Faverge committed
158 159
    if (chameleon_desc_islocal(A, Am, An)) \
        __chameleon_exec = 1;
160 161 162

#define RUNTIME_PRUNING_STATS_END_ACCESS_DECLARATION \
    RUNTIME_total_tasks++; \
Mathieu Faverge's avatar
Mathieu Faverge committed
163
    if (__chameleon_exec) \
164
        RUNTIME_exec_tasks++; \
Mathieu Faverge's avatar
Mathieu Faverge committed
165
    else if (__chameleon_need_submit) \
166
        RUNTIME_comm_tasks++; \
Mathieu Faverge's avatar
Mathieu Faverge committed
167
    else if (__chameleon_changed) \
168 169 170
        RUNTIME_changed_tasks++;

#define RUNTIME_PRUNING_STATS_RANK_CHANGED(rank) \
Mathieu Faverge's avatar
Mathieu Faverge committed
171 172 173 174
    int __chameleon_myrank; \
    RUNTIME_comm_rank(&__chameleon_myrank); \
    __chameleon_exec = (rank) == __chameleon_myrank; \
    __chameleon_changed = 1; \
175

176 177 178 179
#else
#define RUNTIME_PRUNING_STATS_BEGIN_ACCESS_DECLARATION
#define RUNTIME_PRUNING_STATS_ACCESS_W(A, Am, An)
#define RUNTIME_PRUNING_STATS_END_ACCESS_DECLARATION
180
#define RUNTIME_PRUNING_STATS_RANK_CHANGED(rank)
181 182
#endif

183
#define RUNTIME_BEGIN_ACCESS_DECLARATION        \
184 185
    RUNTIME_PRUNING_STATS_BEGIN_ACCESS_DECLARATION

186
#define RUNTIME_ACCESS_R(A, Am, An)
187

188 189 190
#define RUNTIME_ACCESS_W(A, Am, An)             \
    RUNTIME_PRUNING_STATS_ACCESS_W(A, Am, An);  \
    RUNTIME_ACCESS_WRITE_CACHED(A, Am, An)
191

192 193 194
#define RUNTIME_ACCESS_RW(A, Am, An)            \
    RUNTIME_PRUNING_STATS_ACCESS_W(A, Am, An);  \
    RUNTIME_ACCESS_WRITE_CACHED(A, Am, An)
195

196
#define RUNTIME_RANK_CHANGED(rank)              \
197
    RUNTIME_PRUNING_STATS_RANK_CHANGED(rank)
198

199
#define RUNTIME_END_ACCESS_DECLARATION          \
200
    RUNTIME_PRUNING_STATS_END_ACCESS_DECLARATION;
201

202
#endif /* _chameleon_starpu_h_ */