From c36b90bfc84adde606897b7edbbe7cc943571a16 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 4 Jun 2014 16:36:14 +0200 Subject: [PATCH] add --opencl-include-file option In the next commit, we will pull in changes in pet that make it possible to specify function summaries. In order to be able to exploit this functionality, we need to be able to tell the OpenCL compiler where to find the function bodies for the functions that are being called (and for which summary functions may be specified). Signed-off-by: Sven Verdoolaege --- README | 17 +++++++++++++++++ opencl.c | 7 ++++++- ppcg_options.c | 3 +++ ppcg_options.h | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README b/README index a0ecb63..ca85802 100644 --- a/README +++ b/README @@ -139,6 +139,23 @@ We have experienced no such freezes when using AMD, ARM or Intel OpenCL libraries. +Function calls + +Function calls inside the analyzed fragment are reproduced +in the CUDA or OpenCL code, but for now it is left to the user +to make sure that the functions that are being called are +available from the generated kernels. + +In the case of OpenCL code, the --opencl-include-file option +may be used to specify one or more files to be #include'd +from the generated code. These files may then contain +the definitions of the functions being called from the +program fragment. If the pathnames of the included files +are relative to the current directory, then you may need +to additionally specify the --opencl-compiler-options=-I. +to make sure that the files can be found by the OpenCL compiler. + + Processing PolyBench When processing a PolyBench/C 3.2 benchmark, you should always specify diff --git a/opencl.c b/opencl.c index b81fe0c..3f0e872 100644 --- a/opencl.c +++ b/opencl.c @@ -59,13 +59,15 @@ static FILE *open_or_croak(const char *name) /* Open the host .c file and the kernel .h and .cl files for writing. * Their names are derived from info->output (or info->input if * the user did not specify an output file name). - * Add the necessary includes to these files. + * Add the necessary includes to these files, including those specified + * by the user. * * Return 0 on success and -1 on failure. */ static int opencl_open_files(struct opencl_info *info) { char name[PATH_MAX]; + int i; int len; if (info->output) { @@ -109,6 +111,9 @@ static int opencl_open_files(struct opencl_info *info) "const char *opencl_options);\n"); fprintf(info->kernel_h, "const char *opencl_error_string(cl_int error);\n"); + for (i = 0; i < info->options->opencl_n_include_file; ++i) + fprintf(info->kernel_c, "#include <%s>\n", + info->options->opencl_include_files[i]); return 0; } diff --git a/ppcg_options.c b/ppcg_options.c index 505ecb0..bcb16fe 100644 --- a/ppcg_options.c +++ b/ppcg_options.c @@ -32,6 +32,9 @@ ISL_ARG_STR(struct ppcg_options, opencl_compiler_options, 0, "compiler-options", "options", NULL, "options to pass to the OpenCL compiler") ISL_ARG_BOOL(struct ppcg_options, opencl_use_gpu, 0, "use-gpu", 1, "use GPU device (if available)") +ISL_ARG_STR_LIST(struct ppcg_options, opencl_n_include_file, + opencl_include_files, 0, "include-file", "filename", + "file to #include in generated OpenCL code") ISL_ARGS_END ISL_ARGS_START(struct ppcg_options, ppcg_options_args) diff --git a/ppcg_options.h b/ppcg_options.h index 8fc3a49..80ea0b3 100644 --- a/ppcg_options.h +++ b/ppcg_options.h @@ -45,6 +45,10 @@ struct ppcg_options { char *opencl_compiler_options; /* Prefer GPU device over CPU. */ int opencl_use_gpu; + /* Number of files to include. */ + int opencl_n_include_file; + /* Files to include. */ + const char **opencl_include_files; }; ISL_ARG_DECL(ppcg_debug_options, struct ppcg_debug_options, -- 2.11.4.GIT