From e7238fa16247b334b40e7ca8be1f5df92f570392 Mon Sep 17 00:00:00 2001 From: Dimitris Karkoulis Date: Mon, 25 Jun 2012 02:10:40 +0200 Subject: [PATCH] Few fixes on logs and the toolbox Comments need to be updated --- openCL/ocl_base.cpp | 6 ++ openCL/ocl_tools/cLogger/cLogger.c | 64 +++++++++++++++++- openCL/ocl_tools/cLogger/cLogger.h | 1 + openCL/ocl_tools/ocl_tools.cc | 101 ++++++++++++++++++----------- 4 files changed, 133 insertions(+), 39 deletions(-) diff --git a/openCL/ocl_base.cpp b/openCL/ocl_base.cpp index dbfae13b..d82105fa 100644 --- a/openCL/ocl_base.cpp +++ b/openCL/ocl_base.cpp @@ -79,6 +79,8 @@ ocl::ocl(FILE *stream, const char *fname, int safe, int depth, int perf_time, in cLog_date(&hLog,LOGDNONE); usesStdout = 0; + if(static_cast(depth) >= LOGDBASIC) cLog_log_configuration(&hLog); + ContructorInit(); setDocstring("OpenCL base functionality for xrpd1d. \nFeel free to play around but you will not be able to perform integrations"\ "at this level.\nYou may check the OpenCL platforms and devices found in your system at this point. Try print_devices\n"\ @@ -102,6 +104,8 @@ ocl::ocl(const char *fname, const char *identity):exec_identity(identity) cLog_date(&hLog,LOGDNONE); usesStdout = 0; + cLog_log_configuration(&hLog); + ContructorInit(); setDocstring("OpenCL base functionality for xrpd1d. \nFeel free to play around but you will not be able to perform integrations"\ "at this level.\nYou may check the OpenCL platforms and devices found in your system at this point. Try print_devices\n"\ @@ -121,6 +125,8 @@ ocl::ocl():exec_identity(NULL){ cLog_date(&hLog,LOGDNONE); usesStdout = 1; + cLog_report_configuration(&hLog); + ContructorInit(); setDocstring("OpenCL base functionality for xrpd1d. \nFeel free to play around but you will not be able to perform integrations"\ "at this level.\nYou may check the OpenCL platforms and devices found in your system at this point. Try print_devices\n"\ diff --git a/openCL/ocl_tools/cLogger/cLogger.c b/openCL/ocl_tools/cLogger/cLogger.c index 81830d4e..fd43f7ff 100644 --- a/openCL/ocl_tools/cLogger/cLogger.c +++ b/openCL/ocl_tools/cLogger/cLogger.c @@ -119,7 +119,7 @@ void cLog_init(logger_t *hLog, FILE *stream, const char *fname, int severity, en "| a filename is not set and cLog will be disabled. |\n" "| All messages through cLog will be directed to stdout |\n" "| or stderr (for critical messages). |\n" - "\--------------------------------------------------------/\n" + "\\--------------------------------------------------------/\n" "\n" ); @@ -320,6 +320,23 @@ void cLog_critical(logger_t *hLog, const char * format, ...) return; } +void cLog(logger_t *hLog, enum_LOGDEPTH depth, const char * format, ...) +{ + va_list argp; + + if( ((*hLog).depth >= depth) && ((*hLog).status == 1) ) + { + va_start(argp,format); + if((*hLog).timestamps)fprintf((*hLog).stream,"%s ",get_timestamp()); + + fflush((*hLog).stream); + vfprintf((*hLog).stream,format,argp); + fflush((*hLog).stream); + va_end(argp); + } + return; +} + void cLog_bench(logger_t *hLog, const char * format, ...) { va_list argp; @@ -362,7 +379,7 @@ void cLog_report_configuration(logger_t *hLog) { if( (*hLog).stream == stdout )printf("- Stream: stdout \n"); else if( (*hLog).stream == stderr )printf("- Stream: stderr \n"); - else printf("- Stream: s% \n", (*hLog).fname); + else printf("- Stream: %s \n", (*hLog).fname); printf("- Speed: %s\n",((*hLog).type)?"SAFE":"FAST"); printf("- Depth: "); @@ -393,4 +410,47 @@ void cLog_report_configuration(logger_t *hLog) }else printf("- Not Initialised \n"); printf("\n"); + return; } + +void cLog_log_configuration(logger_t *hLog) +{ + + if( (!hLog) || (*hLog).status == 0 ) return; + else + { + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"\n"); + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"cLogger Configuration\n"); + if( (*hLog).stream == stdout )cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Stream: stdout \n"); + else if( (*hLog).stream == stderr )cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Stream: stderr \n"); + else cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Stream: %s \n", (*hLog).fname); + + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Speed: %s\n",((*hLog).type)?"SAFE":"FAST"); + switch ( (enum_LOGDEPTH)(*hLog).depth ) + { + case LOGDNONE: + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Depth: Nothing \n"); + break; + case LOGDONLYERRORS: + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Depth: Errors \n"); + break; + case LOGDBASIC: + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Depth: Basic \n"); + break; + case LOGDEXTENDED: + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Depth: Extended \n"); + break; + case LOGDDEBUG: + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Depth: Debug \n"); + break; + default: + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Depth: Undefined \n"); + break; + } + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Profiling Information: %s\n",((*hLog).perf)?"YES":"NO"); + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"- Timestamps: %s\n",((*hLog).timestamps)?"YES":"NO"); + + cLog(hLog, (enum_LOGDEPTH)(*hLog).depth,"\n"); + } + return; +} \ No newline at end of file diff --git a/openCL/ocl_tools/cLogger/cLogger.h b/openCL/ocl_tools/cLogger/cLogger.h index 8cbd5750..81170593 100644 --- a/openCL/ocl_tools/cLogger/cLogger.h +++ b/openCL/ocl_tools/cLogger/cLogger.h @@ -79,6 +79,7 @@ DllInterface void cLog_date_text(logger_t *hLog, enum_LOGDEPTH depth, const char DllInterface void cLog_init(logger_t *hLog, FILE *stream, const char *fname, int severity, enum_LOGTYPE type, enum_LOGDEPTH depth, int perf, int timestamps); DllInterface void cLog_fin(logger_t *hLog); DllInterface void cLog_report_configuration(logger_t *hLog); +DllInterface void cLog_log_configuration(logger_t *hLog); #ifdef __cplusplus } diff --git a/openCL/ocl_tools/ocl_tools.cc b/openCL/ocl_tools/ocl_tools.cc index 5554871e..2512dd10 100644 --- a/openCL/ocl_tools/ocl_tools.cc +++ b/openCL/ocl_tools/ocl_tools.cc @@ -811,9 +811,26 @@ return 0; int ocl_compiler(ocl_config_type *oclconfig,const char *kernelfilename,int BLOCK_SIZE,const char *optional) { + char compiler_options_flush[10000]; + char compiler_options_temp[10000]; FILE *kernel; - cl_int err; + cl_int err; + + if(BLOCK_SIZE > 9999){ + cLog_critical(oclconfig->hLog,"Blocksize too big"); + return -2; + } + + size_t optlen=0; + size_t complen=strlen(oclconfig->compiler_options) +2; + size_t deflen=strlen("-I. -D BLOCK_SIZE=9999 ") + 2; + + if(optional) optlen = strlen(optional) + 2; + if(optlen + complen + deflen > 9999){ + cLog_critical(oclconfig->hLog,"Compile string is too long\n"); + return -2; + } oclconfig->kernelstring_lens = (size_t*)malloc(1*sizeof(size_t)); oclconfig->kernelstrings = (char**)malloc(1*sizeof(char)); @@ -837,44 +854,51 @@ int ocl_compiler(ocl_config_type *oclconfig,const char *kernelfilename,int BLOCK (const char**)&oclconfig->kernelstrings[0],(const size_t*)&oclconfig->kernelstring_lens[0],&err); if(err)cLog_critical(oclconfig->hLog,"%s\n",ocl_perrc(err)); - //Compile the program - char *compiler_options_flush; - char *compiler_options_temp; - compiler_options_flush = (char*)malloc(10000*sizeof(char)); - compiler_options_temp = (char*)malloc(10000*sizeof(char)); sprintf(compiler_options_temp,"-I. -D BLOCK_SIZE=%d %s",BLOCK_SIZE,oclconfig->compiler_options); if(optional) sprintf(compiler_options_flush,"%s %s",compiler_options_temp,optional); else sprintf(compiler_options_flush,"%s",compiler_options_temp); cLog_debug(oclconfig->hLog,"Compiler options: %s\n",compiler_options_flush); + //Compile the program err = clBuildProgram(oclconfig->oclprogram, 1, &oclconfig->ocldevice, compiler_options_flush, 0, 0); - free(compiler_options_flush); + + char *buildinfo; + size_t binf_size; if(err){ - char buildinfo[100000]; cLog_critical(oclconfig->hLog,"clBuildProgram has failed: %s\n",ocl_perrc(err)); - CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_LOG,sizeof(buildinfo),&buildinfo,NULL), - oclconfig->hLog); + CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_LOG,0,NULL,&binf_size), + oclconfig->hLog); + buildinfo = (char *)malloc((binf_size+1)*sizeof(char)); + CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_LOG,binf_size,buildinfo,NULL), + oclconfig->hLog); + + buildinfo[binf_size] = '\0'; + cLog_critical(oclconfig->hLog,"clBuildProgram log:\n"); cLog_critical(oclconfig->hLog,"%s\n",buildinfo); + cLog_critical(oclconfig->hLog,"End of clBuildProgram log\n"); + free(buildinfo); return -1; //Fallback } else{ - char buildinfo[100000]; - cl_build_status build_status; + cl_build_status build_status; CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_STATUS,sizeof(build_status),&build_status,NULL), oclconfig->hLog); - cLog_debug(oclconfig->hLog,"clBuildProgram was successful: \n"); - cLog_debug(oclconfig->hLog,"------------------------------------------------------------\n"); - if(build_status==CL_BUILD_SUCCESS)cLog_debug(oclconfig->hLog,"CL_BUILD_SUCCESS\n"); - else if (build_status==CL_BUILD_NONE)cLog_debug(oclconfig->hLog,"CL_BUILD_NONEd\n"); - else if (build_status==CL_BUILD_IN_PROGRESS)cLog_debug(oclconfig->hLog,"CL_BUILD_IN_PROGRESS\n"); - CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_LOG,sizeof(buildinfo),&buildinfo,NULL), + cLog_debug(oclconfig->hLog,"clBuildProgram was successful: %s\n",ocl_perrc(err) ); + CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_LOG,0,NULL,&binf_size), oclconfig->hLog); - - cLog_debug(oclconfig->hLog,"%s\n",buildinfo); - cLog_debug(oclconfig->hLog,"------------------------------------------------------------\n"); - + buildinfo = (char *)malloc((binf_size+1)*sizeof(char)); + CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_LOG,binf_size,buildinfo,NULL), + oclconfig->hLog); + buildinfo[binf_size] = '\0'; + if(binf_size >3) + { + cLog_debug(oclconfig->hLog,"clBuildProgram log:\n"); + cLog_debug(oclconfig->hLog,"%s\n",buildinfo); + cLog_debug(oclconfig->hLog,"End of clBuildProgram log\n"); + } + free(buildinfo); } return 0; } @@ -972,7 +996,9 @@ int ocl_compiler(ocl_config_type *oclconfig,const char **clList,int clNum,int BL oclconfig->hLog); buildinfo[binf_size] = '\0'; + cLog_critical(oclconfig->hLog,"clBuildProgram log:\n"); cLog_critical(oclconfig->hLog,"%s\n",buildinfo); + cLog_critical(oclconfig->hLog,"End of clBuildProgram log\n"); free(buildinfo); return -1; //Fallback } else{ @@ -980,21 +1006,20 @@ int ocl_compiler(ocl_config_type *oclconfig,const char **clList,int clNum,int BL CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->prgs[clfile].oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_STATUS,sizeof(build_status),&build_status,NULL), oclconfig->hLog); - cLog_debug(oclconfig->hLog,"clBuildProgram was successful: \n"); - cLog_debug(oclconfig->hLog,"------------------------------------------------------------\n"); - if(build_status==CL_BUILD_SUCCESS)cLog_debug(oclconfig->hLog,"CL_BUILD_SUCCESS\n"); - else if (build_status==CL_BUILD_NONE)cLog_debug(oclconfig->hLog,"CL_BUILD_NONEd\n"); - else if (build_status==CL_BUILD_IN_PROGRESS)cLog_debug(oclconfig->hLog,"CL_BUILD_IN_PROGRESS\n"); + cLog_debug(oclconfig->hLog,"clBuildProgram was successful: %s\n",ocl_perrc(err) ); CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->prgs[clfile].oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_LOG,0,NULL,&binf_size), oclconfig->hLog); buildinfo = (char *)malloc((binf_size+1)*sizeof(char)); CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->prgs[clfile].oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_LOG,binf_size,buildinfo,NULL), oclconfig->hLog); buildinfo[binf_size] = '\0'; - cLog_debug(oclconfig->hLog,"%s\n",buildinfo); + if(binf_size >3) + { + cLog_debug(oclconfig->hLog,"clBuildProgram log:\n"); + cLog_debug(oclconfig->hLog,"%s\n",buildinfo); + cLog_debug(oclconfig->hLog,"End of clBuildProgram log\n"); + } free(buildinfo); - cLog_debug(oclconfig->hLog,"------------------------------------------------------------\n"); - } } return 0; @@ -1081,7 +1106,9 @@ int ocl_compiler(ocl_config_type *oclconfig,unsigned char **clList,unsigned int oclconfig->hLog); buildinfo[binf_size] = '\0'; + cLog_critical(oclconfig->hLog,"clBuildProgram log:\n"); cLog_critical(oclconfig->hLog,"%s\n",buildinfo); + cLog_critical(oclconfig->hLog,"End of clBuildProgram log\n"); free(buildinfo); return -1; //Fallback } else{ @@ -1089,11 +1116,7 @@ int ocl_compiler(ocl_config_type *oclconfig,unsigned char **clList,unsigned int CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->prgs[clfile].oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_STATUS,sizeof(build_status),&build_status,NULL), oclconfig->hLog); - cLog_debug(oclconfig->hLog,"clBuildProgram was successful: \n"); - cLog_debug(oclconfig->hLog,"------------------------------------------------------------\n"); - if(build_status==CL_BUILD_SUCCESS)cLog_debug(oclconfig->hLog,"CL_BUILD_SUCCESS\n"); - else if (build_status==CL_BUILD_NONE)cLog_debug(oclconfig->hLog,"CL_BUILD_NONEd\n"); - else if (build_status==CL_BUILD_IN_PROGRESS)cLog_debug(oclconfig->hLog,"CL_BUILD_IN_PROGRESS\n"); + cLog_debug(oclconfig->hLog,"clBuildProgram was successful: %s\n",ocl_perrc(err)); CL_CHECK_PRN (clGetProgramBuildInfo (oclconfig->prgs[clfile].oclprogram,oclconfig->ocldevice,CL_PROGRAM_BUILD_LOG,0,NULL,&binf_size), oclconfig->hLog); @@ -1102,9 +1125,13 @@ int ocl_compiler(ocl_config_type *oclconfig,unsigned char **clList,unsigned int oclconfig->hLog); buildinfo[binf_size] = '\0'; - cLog_debug(oclconfig->hLog,"%s\n",buildinfo); + if(binf_size >3) + { + cLog_debug(oclconfig->hLog,"clBuildProgram log:\n"); + cLog_debug(oclconfig->hLog,"%s\n",buildinfo); + cLog_debug(oclconfig->hLog,"End of clBuildProgram log\n"); + } free(buildinfo); - cLog_debug(oclconfig->hLog,"------------------------------------------------------------\n"); } }