00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef TMH_MTH_OPENCL_H
00029 #define TMH_MTH_OPENCL_H
00030
00031 #include<stdlib.h>
00032 #include<stdio.h>
00033
00034 #include <CL/cl.h>
00035
00036
00037
00038 #define TMC_OCL_ALL_PLATFORMS -1 // for future use
00039
00040 #define TMC_OCL_ALL_DEVICES -1 // for future use
00041 #define TMC_OCL_DEVICE_CPU 0 // (for OPENCL_CPU compile time switch)
00042 #define TMC_OCL_DEVICE_GPU 1 // (for OPENCL_GPU compile time switch)
00043 #define TMC_OCL_DEVICE_ACCELERATOR 2 // (for OPENCL_PHI compile time switch)
00044
00045 #define TMC_OCL_MAX_NUM_KERNELS 10
00046
00047
00048 #define TMC_OCL_KERNEL_NUM_INT_INDEX 0
00049 #define TMC_OCL_KERNEL_CRS_FINALIZE 1
00050 #define TMC_OCL_KERNEL_SOLVE 2
00051 #define TMC_OCL_KERNEL_REWRITE_GEO 3
00052
00053
00054 #ifdef __cplusplus
00055 extern "C" {
00056 #endif
00057
00058
00059
00060 typedef struct {
00061
00062 cl_device_id id;
00063 int context_index;
00064 int tmc_type;
00065 cl_device_type type;
00066 double global_mem_bytes;
00067 double global_max_alloc;
00068 double shared_mem_bytes;
00069 double constant_mem_bytes;
00070 double cache_bytes;
00071 int cache_line_bytes;
00072 int max_num_comp_units;
00073 int max_work_group_size;
00074 cl_command_queue command_queue;
00075 int number_of_kernels;
00076 cl_program program[TMC_OCL_MAX_NUM_KERNELS];
00077 cl_kernel kernel[TMC_OCL_MAX_NUM_KERNELS];
00078 } tmt_ocl_device_struct;
00079
00080 typedef struct {
00081
00082 cl_platform_id id;
00083
00084 int number_of_devices;
00085 tmt_ocl_device_struct *list_of_devices;
00086 cl_context list_of_contexts[3];
00087 } tmt_ocl_platform_struct;
00088
00089 typedef struct {
00090
00091
00092 int number_of_platforms;
00093 tmt_ocl_platform_struct* list_of_platforms;
00094 int current_platform_index;
00095 int current_device_type;
00096 int current_device;
00097 char kernel_source_directory;
00098 } tmt_ocl_struct;
00099
00100
00101
00102 extern tmt_ocl_struct tmv_ocl_struct;
00103
00104
00105
00109 extern int tmr_ocl_init(
00110 char* Work_dir,
00111 FILE *Interactive_input,
00112 FILE *Interactive_output,
00113 int Control,
00114 int Monitor
00115 );
00116
00117
00121 extern int tmr_ocl_create_contexts(
00122 FILE *Interactive_output,
00123 int Chosen_platform_id,
00124 int Monitor
00125 );
00126
00130 extern int tmr_ocl_create_command_queues(
00131 FILE *Interactive_output,
00132 int Chosen_platform_index,
00133 int Chosen_device_type,
00134 int Monitor
00135 );
00136
00140 extern int tmr_ocl_create_kernel(
00141 FILE *Interactive_output,
00142 int Platform_index,
00143 int Device_index,
00144 int Kernel_index,
00145 char* Kernel_name,
00146 const char* FileName,
00147 int Monitor
00148 );
00149
00150
00151
00152
00153 extern char* tmr_ocl_readSource(
00154 FILE *Interactive_output,
00155 const char* kernelPath
00156 );
00157
00161 extern int tmr_ocl_get_current_platform_index();
00162
00167 extern int tmr_ocl_get_current_device_type();
00168
00173 extern int tmr_ocl_get_current_device();
00174
00175
00181 extern int tmr_ocl_select_device(
00182 FILE* Interactive_output,
00183 int Platform_index,
00184 int Device_tmc_type
00185 );
00186
00190 extern int tmr_ocl_device_type(
00191 int Platform_index,
00192 int Device_index
00193 );
00194
00198 extern cl_device_id tmr_ocl_select_device_id(
00199 int Platform_index,
00200 int Device_index
00201 );
00202
00206 extern cl_context tmr_ocl_select_context(
00207 int Platform_index,
00208 int Device_index
00209 );
00210
00214 extern cl_command_queue tmr_ocl_select_command_queue(
00215 int Platform_index,
00216 int Device_index
00217 );
00218
00222 extern cl_kernel tmr_ocl_select_kernel(
00223 int Platform_index,
00224 int Device_index,
00225 int Kernel_index
00226 );
00227
00228
00232 extern void tmr_ocl_cleanup();
00233
00234
00235
00236
00237
00238 extern void tmr_kernel_execution_log(cl_int error_code, int line_code, const char *function_name);
00239
00240
00241
00242
00243 extern void tmr_set_kernel_arguments_log(cl_int error_code, int argument_index, int line_code, const char *function_name);
00244
00245
00246 #ifdef __cplusplus
00247 }
00248 #endif
00249
00250
00251 #endif