00001 /************************************************************************ 00002 File tmh_ocl_num_int.h - OpenCL interface to numerical integration and solution procedures 00003 00004 Contains declarations of constants, types and interface routines: 00005 00006 tmr_ocl_create_num_int_kernel - for a selected platform, device and kernel index 00007 tmr_ocl_create_assembly_structures - create all necessary for numerical integration 00008 and assembling data structures in host and accelerator memory 00009 tmr_ocl_free_assembly_structures - free numerical integration 00010 and assembling data structures created by tmr_ocl_create_assembly_structures 00011 tmr_ocl_create_assemble_stiff_mat_elem - create local element stiffness matrices 00012 and possibly assemble them to the global stiffness matrix 00013 tmr_ocl_create_solver_structures_crs - to create CRS structure on ACCELERATOR 00014 tmr_ocl_free_solver_structures_crs - to release CRS structure on ACCELERATOR 00015 00016 History: 00017 02.2013 - Krzysztof Banas, initial version 00018 10.2016 - Jan Bielanski, Kazimierz Chlon - assembling into crs on gpu 00019 00020 ------------------------------ 00021 History: 00022 02.2013 - Krzysztof Banas, initial version 00023 00024 *************************************************************************/ 00025 00026 #ifndef TMH_OPENCL_NUM_INT_H 00027 #define TMH_OPENCL_NUM_INT_H 00028 00029 #include<stdlib.h> 00030 #include<stdio.h> 00031 00032 #include <CL/cl.h> 00033 00034 /* Constants */ 00035 // float versus double (MUST BE COMPATIBLE WITH KERNEL SWITCH!!!!) 00036 // data type for integration and assembly 00037 //#define SCALAR float 00038 #define SCALAR double 00039 00040 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif 00044 00045 typedef struct { 00046 // Classic tables 00047 double *crs_val_cpu; 00048 double *crs_val_gpu; 00049 unsigned int *crs_col_ind; 00050 unsigned int *crs_row_ptr; 00051 double *rhs_val_cpu; 00052 double *rhs_val_gpu; 00053 00054 int Nnz; //Non zero values in crs 00055 int Nrdof; //Global number of DOFs 00056 00057 // OpenCL CRS memory objects 00058 cl_mem ocl_crs_val; 00059 cl_mem ocl_crs_external_val; 00060 cl_mem ocl_crs_col_ind; 00061 cl_mem ocl_crs_row_ptr; 00062 00063 // CRS size of data 00064 int ocl_crs_val_bytes; 00065 int ocl_crs_col_ind_bytes; 00066 int ocl_crs_row_ptr_bytes; 00067 00068 // OpenCL RHS vector 00069 cl_mem ocl_rhs_val; 00070 cl_mem ocl_rhs_external_val; 00071 00072 // RHS size of data 00073 int ocl_rhs_bytes; 00074 00075 00076 } tmt_ocl_crs_struct; 00077 00078 typedef struct { 00079 00080 // OpenCL assembly table memory objects 00081 cl_mem ocl_asse_pos_first_dof_int_ent; 00082 cl_mem ocl_assembly_table; 00083 00084 int nr_asse_blocks_all_int_ent; 00085 int ocl_asse_pos_first_dof_int_ent_bytes; 00086 int ocl_assembly_table_bytes; 00087 00088 cl_mem ocl_local_to_global; 00089 cl_mem ocl_global_to_posglob; 00090 cl_mem ocl_pos_first_dof_int_ent; 00091 int ocl_local_to_global_bytes; 00092 00093 } tmt_ocl_assembly_struct; 00094 00095 typedef struct { 00096 00097 // Geometric data - stored by elements 00098 int nr_geo; int ocl_el_geo_data_in_size; 00099 int ocl_el_geo_data_in_bytes; 00100 cl_mem ocl_el_geo_data_in; 00101 00102 // Geometric data - strored by dofs id 00103 int ocl_el_geo_data_by_dofs_in_size; 00104 int ocl_el_geo_data_by_dofs_in_bytes; 00105 cl_mem ocl_el_geo_data_by_dofs_in; 00106 00107 // Gauss data 00108 int ngauss; int ocl_gauss_data_in_size; 00109 int ocl_gauss_data_in_bytes; 00110 cl_mem ocl_gauss_data_in; 00111 00112 // Shape fun data 00113 int nshape; int ocl_shape_fun_data_in_size; 00114 int ocl_shape_fun_data_in_bytes; 00115 cl_mem ocl_shape_fun_data_in; 00116 00117 //PDE data 00118 int all_el_pde_coeff_size; 00119 int one_el_pde_coeff_size; 00120 int one_int_p_pde_coeff_size; 00121 int ocl_el_pde_dat_in_bytes; 00122 cl_mem ocl_el_pde_data_in; 00123 00124 // CPU only: 00125 int* ngeo_color_pos; 00126 00127 } tmt_ocl_num_int_struct; 00128 00129 typedef struct { 00130 00131 // OpenCL solution table memory objects 00132 cl_mem ocl_dofs_vector_current; 00133 cl_mem ocl_dofs_vector_prev_iter; 00134 cl_mem ocl_dofs_vector_prev_step; 00135 00136 int nrdofs; 00137 00138 } tmt_ocl_solution_struct; 00139 00140 00141 00142 typedef struct { 00143 00144 tmt_ocl_crs_struct crs_struct; 00145 tmt_ocl_assembly_struct assembly_struct; 00146 tmt_ocl_num_int_struct num_int_struct; 00147 tmt_ocl_solution_struct solution_struct; 00148 00149 } tmt_ocl_problem_struct; 00150 00151 /* A single (for the time being) global structure for solving a single problem */ 00152 extern tmt_ocl_problem_struct tmv_ocl_problem_struct; 00153 00154 /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */ 00155 /* -------------- specific procedures for numerical integration ------------------ */ 00156 00157 /*--------------------------------------------------------- 00158 tmr_ocl_create_num_int_kernel - for a selected platform, device and kernel index 00159 ---------------------------------------------------------*/ 00160 extern int tmr_ocl_create_num_int_kernel( 00161 int Platform_index, 00162 int Device_index, 00163 int Kernel_index, 00164 char* Kernel_name, 00165 const char* Kernel_file, 00166 int Monitor 00167 ); 00168 00169 00170 /*--------------------------------------------------------- 00171 tmr_ocl_create_assembly_structures - create all necessary for numerical integration 00172 and assembling data structures in host and accelerator memory 00173 ----------------------------------------------------------*/ 00174 extern int tmr_ocl_create_assembly_structures( 00175 ); 00176 00177 /*--------------------------------------------------------- 00178 tmr_ocl_free_assembly_structures - free numerical integration 00179 and assembling data structures created by tmr_ocl_create_assembly_structures 00180 ----------------------------------------------------------*/ 00181 extern int tmr_ocl_free_assembly_structures( 00182 ); 00183 00184 /*--------------------------------------------------------- 00185 tmr_ocl_create_assemble_stiff_mat_elem - create local element stiffness matrices 00186 and possibly assemble them to the global stiffness matrix 00187 ----------------------------------------------------------*/ 00188 extern int tmr_ocl_create_assemble_stiff_mat_elem( 00189 int Problem_id, 00190 //int Level_id, 00191 int Comp_type, /* in: indicator for the scope of computations: */ 00192 //extern const int PDC_NO_COMP ; /* do not compute stiff matrix and rhs vector */ 00193 //extern const int PDC_COMP_SM ; /* compute entries to stiff matrix only */ 00194 //extern const int PDC_COMP_RHS ; /* compute entries to rhs vector only */ 00195 //extern const int PDC_COMP_BOTH; /* compute entries for sm and rhsv */ 00196 int* Pdeg_coarse_p, // indicator or value for pdeg on coarse meshes 00197 00198 //int Nr_int_ent, 00199 //int* L_int_ent_type, 00200 //int* L_int_ent_id, 00201 00202 //int Nr_colors_elems, 00203 //int* L_color_index_elems, 00204 00205 //int Nr_colors_accel, 00206 //int* Asse_pos_first_dof_int_ent, 00207 //int* Assembly_table, 00208 //int* Pos_first_dof_int_ent, 00209 00210 //int* Local_to_global, 00211 //int Max_dofs_int_ent 00212 00213 // Number of elements per color 00214 int Nr_elems, 00215 00216 // Index of first element in assembly table for color 00217 int First_asse_elem_index, 00218 00219 // Index of first geo for color 00220 int First_geo_index, 00221 00222 // Index of first pde for color 00223 int First_pde_index 00224 ); 00225 /*--------------------------------------------------------- 00226 tmr_ocl_create_solver_structures_crs - to create CRS structure on ACCELERATOR 00227 ----------------------------------------------------------*/ 00228 extern int tmr_ocl_create_solver_structures_crs( 00229 ); 00230 00231 00232 /*--------------------------------------------------------- 00233 tmr_ocl_free_solver_structures_crs - to release CRS structure on ACCELERATOR 00234 ----------------------------------------------------------*/ 00235 extern int tmr_ocl_free_solver_structures_crs( 00236 ); 00237 00238 /*--------------------------------------------------------- 00239 tmr_ocl_get_solver_structures_crs - to get CRS structure on ACCELERATOR 00240 /*---------------------------------------------------------*/ 00241 extern int tmr_ocl_get_solver_structures_crs( 00242 int* nnz, 00243 cl_mem* crs_col_ind, 00244 cl_mem* crs_row_ptr, 00245 cl_mem* crs_val, 00246 cl_mem* rhs ); 00247 00248 00249 //tmr_ocl_send_data_to_gpu_crs ?????????? 00250 00251 //tmr_ocl_prepare_final_crs ????????????? tmr_ocl_merge_solver_structures 00252 00253 //tmr_ocl_solve_viennacl_gpu ???????????? 00254 00261 /* /\**-------------------------------------------------------- */ 00262 /* tmr_ocl_num_int_cleanup - discards created OpenCL resources */ 00263 /* ---------------------------------------------------------*\/ */ 00264 /* extern void tmr_ocl_num_int_cleanup(); */ 00265 00266 00267 00268 /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */ 00269 /* -------------- TEMPORARY jb_kc_opencl version ------------------ */ 00270 00271 /* /\*--------------------------------------------------------- */ 00272 /* tmr_perform_creation_crs - create crs structure on gpu */ 00273 /* ---------------------------------------------------------*\/ */ 00274 /* int tmr_perform_creation_crs( */ 00275 /* int Problem_id, */ 00276 /* int Nr_int_ent, */ 00277 /* int* Asse_pos_first_dof_int_ent, */ 00278 /* int* Assembly_table, */ 00279 /* int Max_dofs_int_ent */ 00280 /* //,tmt_ocl_crs_struct *tmv_ocl_crs_struct - currently structure is global defined */ 00281 /* ); */ 00282 00283 00284 /* /\*--------------------------------------------------------- */ 00285 /* tmr_send_data_to_gpu_crs - send */ 00286 /* ---------------------------------------------------------*\/ */ 00287 /* int tmr_prepare_final_crs(); */ 00288 00289 /* /\*--------------------------------------------------------- */ 00290 /* tmr_cleanup_crs - free tmr crs structure */ 00291 /* ---------------------------------------------------------*\/ */ 00292 /* int tmr_cleanup_crs(); */ 00293 00294 /* /\*--------------------------------------------------------- */ 00295 /* tmr_get_crs_structure - get crs structure from lsd */ 00296 /* ---------------------------------------------------------*\/ */ 00297 /* int tmr_get_crs_structure( */ 00298 /* int Nrdof_glob, */ 00299 /* int nnz, */ 00300 /* int* crs_col_ind, */ 00301 /* int* crs_row_ptr, */ 00302 /* double* crs_val, */ 00303 /* double* rhs */ 00304 /* ); */ 00305 00306 /* /\*--------------------------------------------------------- */ 00307 /* tmr_solve_viennacl_gpu - solve on gpu */ 00308 /* ---------------------------------------------------------*\/ */ 00309 /* int tmr_solve_viennacl_gpu(double* X); */ 00310 00311 00312 00313 00314 00315 /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */ 00316 /* -------------- TEMPORARY PORTED FROM include/tmh_accel_intf.h ------------------ */ 00317 00318 00319 /* /\*--------------------------------------------------------- */ 00320 /* tmr_send_geo_data_accel_test - send geo data to accelerator */ 00321 /* ---------------------------------------------------------*\/ */ 00322 /* int tmr_send_geo_data_accel_test( */ 00323 /* int Problem_id, */ 00324 /* int Nr_geo, */ 00325 /* SCALAR* El_geo_dat_host_p // switch to scalar in new code */ 00326 /* ); */ 00327 00328 00329 /* /\*--------------------------------------------------------- */ 00330 /* tmr_cleanup_geo_data_accel_test - remove geo data from accelerator */ 00331 /* ---------------------------------------------------------*\/ */ 00332 /* int tmr_cleanup_geo_data_accel_test( */ 00333 /* int Problem_id, */ 00334 /* int Nr_geo, */ 00335 /* SCALAR* El_geo_dat_host_p */ 00336 /* ); */ 00337 00338 /* /\*--------------------------------------------------------- */ 00339 /* tmr_rewrite_geo_by_color - rewrite geo from dof by dof organization */ 00340 /* to elem by elem organization */ 00341 /* ---------------------------------------------------------*\/ */ 00342 /* int tmr_rewrite_geo_by_color_test( */ 00343 /* int Problem_id, */ 00344 /* int Nr_elems, */ 00345 /* int First_elem_in_color_index, */ 00346 /* int First_geo_in_color_index */ 00347 /* ); */ 00348 00349 00350 00351 /* -------------- TEMPORARY PORTED FROM include/tmh_accel_intf.h ------------------ */ 00352 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ 00353 00354 #ifdef __cplusplus 00355 } 00356 #endif 00357 00358 00359 #endif