backend_manager.hpp 6.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
// **************************************************************************
//
//    PARALUTION   www.paralution.com
//
//    Copyright (C) 2015  PARALUTION Labs UG (haftungsbeschränkt) & Co. KG
//                        Am Hasensprung 6, 76571 Gaggenau
//                        Handelsregister: Amtsgericht Mannheim, HRA 706051
//                        Vertreten durch:
//                        PARALUTION Labs Verwaltungs UG (haftungsbeschränkt)
//                        Am Hasensprung 6, 76571 Gaggenau
//                        Handelsregister: Amtsgericht Mannheim, HRB 721277
//                        Geschäftsführer: Dimitar Lukarski, Nico Trost
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// **************************************************************************



// PARALUTION version 1.1.0 


#ifndef PARALUTION_BACKEND_MANAGER_HPP_
#define PARALUTION_BACKEND_MANAGER_HPP_

#include <iostream>
#include <fstream>

namespace paralution {

template <typename ValueType>
class AcceleratorVector;
template <typename ValueType>
class AcceleratorMatrix;
template <typename ValueType>
class HostMatrix;

/// Backend descriptor - keeps information about the
/// hardware - OpenMP (threads); CUDA (blocksizes, handles, etc);
/// OpenCL (workgroupsizes, handles, etc);
struct Paralution_Backend_Descriptor {

  // set by initbackend();
  bool init;

  // current backend
  int backend;
  bool accelerator;
  bool disable_accelerator;

  // OpenMP threads
  int OpenMP_threads;
  // OpenMP threads before PARALUTION init
  int OpenMP_def_threads;
  // OpenMP nested before PARALUTION init
  int OpenMP_def_nested;
  // Host affinity (true-yes/false-no)
  bool OpenMP_affinity;
  // Host threshold size
  int OpenMP_threshold;

  // GPU section
  // gpu handles
  // cublasHandle_t casted in void **
  void *GPU_cublas_handle;
  // cusparseHandle_t casted in void **
  void *GPU_cusparse_handle;

  int GPU_dev;
  int GPU_warp;
  int GPU_block_size;
  int GPU_max_threads;

  // OCL section
  // ocl handle
  void *OCL_handle;

  int OCL_plat;
  int OCL_dev;
  size_t OCL_max_work_group_size;
  size_t OCL_computeUnits;
  int OCL_warp_size;

  // MIC section
  int MIC_dev;

  // Software marker 
  // DO NOT REMOVE
  char marker[15];
  
  std::ofstream *log_file;
};
  
/// Global backend descriptor
extern struct Paralution_Backend_Descriptor _Backend_Descriptor;

/// Host name
extern const std::string _paralution_host_name [1];

/// Backend names
extern const std::string _paralution_backend_name [4];

/// Backend IDs
enum _paralution_backend_id {None=0,
                             GPU=1,
                             OCL=2,
                             MIC=3};



/// Initialization of the paralution platform
int init_paralution(void);

/// Shutdown the paralution platform
int stop_paralution(void);

/// Select a device
int set_device_paralution(int dev);

/// Set the number of threads in the platform
void set_omp_threads_paralution(int nthreads);

/// Set host affinity (true-on/false-off)
void set_omp_affinity(bool affinity);

/// Set a specific GPU device
void set_gpu_cuda_paralution(int ngpu);

/// Set a specific OpenCL platform and device
void set_ocl_paralution(int nplatform, int ndevice);

/// Set a specific OpenCL platform
void set_ocl_platform_paralution(int platform);

/// Set OpenCL work group size
void set_ocl_work_group_size_paralution(size_t size);

/// Set OpenCL compute units
void set_ocl_compute_units_paralution(size_t cu);

/// Set OpenCL warp size
void set_ocl_warp_size_paralution(int size);

/// Set OpenMP threshold size
void set_omp_threshold(const int threshold);

/// Print information about the platform
void info_paralution(void);

/// Print information about the platform via specific backend descriptor
void info_paralution(const struct Paralution_Backend_Descriptor backend_descriptor);

/// Return true if any accelerator is available
bool _paralution_available_accelerator(void);

/// Disable/Enable the accelerator
void disable_accelerator_paralution(const bool onoff=true);

/// Return backend descriptor
struct Paralution_Backend_Descriptor *_get_backend_descriptor(void);

/// Set backend descriptor
void _set_backend_descriptor(const struct Paralution_Backend_Descriptor backend_descriptor);

/// Set the OMP threads based on the size threshold
void _set_omp_backend_threads(const struct Paralution_Backend_Descriptor backend_descriptor,
                              const int size);

/// Build (and return) a vector on the selected in the descriptor accelerator
template <typename ValueType>
AcceleratorVector<ValueType>* _paralution_init_base_backend_vector(const struct Paralution_Backend_Descriptor backend_descriptor);

/// Build (and return) a matrix on the host
template <typename ValueType>
HostMatrix<ValueType>* _paralution_init_base_host_matrix(const struct Paralution_Backend_Descriptor backend_descriptor,
                                                         const unsigned int matrix_format);

/// Build (and return) a matrix on the selected in the descriptor accelerator
template <typename ValueType>
AcceleratorMatrix<ValueType>* _paralution_init_base_backend_matrix(const struct Paralution_Backend_Descriptor backend_descriptor,
                                                                   const unsigned int matrix_format);

/// Sync the active async transfers
void _paralution_sync(void);

size_t _paralution_add_obj(class ParalutionObj* ptr);
bool _paralution_del_obj(class ParalutionObj* ptr,
                         size_t id);
void _paralution_delete_all_obj(void);
bool _paralution_check_if_any_obj(void);

}

#endif // PARALUTION_BACKEND_MANAGER_HPP_