[Beignet] [PATCH 3/5] runtime: use the "-debug" build option if the debugger is active
Mircea Gherzan
mircea.gherzan at intel.com
Fri Jul 8 12:39:37 UTC 2016
The presence of the debugger is checked for each context instantiation.
All the programs of a context share the same (on/off) state with respect
to kernel debugging.
Signed-off-by: Mircea Gherzan <mircea.gherzan at intel.com>
---
src/cl_context.c | 4 ++++
src/cl_context.h | 2 ++
src/cl_program.c | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/src/cl_context.c b/src/cl_context.c
index a6bde7d..4f1fc87 100644
--- a/src/cl_context.c
+++ b/src/cl_context.c
@@ -38,6 +38,8 @@
#include <assert.h>
#include <string.h>
+#include "intel/intel_debugger.h"
+
#define CHECK(var) \
if (var) \
return CL_INVALID_PROPERTY; \
@@ -151,6 +153,8 @@ cl_create_context(const cl_context_properties * properties,
ctx->user_data = user_data;
cl_driver_set_atomic_flag(ctx->drv, ctx->device->atomic_test_result);
+ ctx->kernel_debug = dbg_is_active();
+
exit:
if (errcode_ret != NULL)
*errcode_ret = err;
diff --git a/src/cl_context.h b/src/cl_context.h
index 489e5d7..4e3c890 100644
--- a/src/cl_context.h
+++ b/src/cl_context.h
@@ -27,6 +27,7 @@
#include "cl_khr_icd.h"
#include <stdint.h>
+#include <stdbool.h>
#include <pthread.h>
/* DRI device created at create context */
@@ -129,6 +130,7 @@ struct _cl_context {
void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *);
/* User's callback when error occur in context */
void *user_data; /* A pointer to user supplied data */
+ bool kernel_debug; /* Flag set if kernel debugging is enabled */
};
diff --git a/src/cl_program.c b/src/cl_program.c
index 644856c..910778e 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -39,6 +39,8 @@
#include <sys/stat.h>
#include <libgen.h>
+#define OPTION_KERNEL_DEBUG "-debug"
+
static void
cl_program_release_sources(cl_program p)
{
@@ -534,12 +536,37 @@ static int check_cl_version_option(cl_program p, const char* options) {
return 1;
}
+static char *
+append_option(const char *options, const char *extra)
+{
+ size_t len;
+ char *opts_debug = NULL;
+
+ if (options) {
+ // Append "-debug" to the user-provided options
+ len = strlen(options) + strlen(extra) + 2;
+ opts_debug = cl_calloc(len, sizeof(char));
+ if (opts_debug)
+ snprintf(opts_debug, len, "%s %s", options, extra);
+ } else {
+ // Create an options string containing only -debug
+ len = strlen(extra) + 1;
+ opts_debug = cl_calloc(len, sizeof(char));
+ if (opts_debug)
+ snprintf(opts_debug, len, "%s", extra);
+ }
+
+ return opts_debug;
+}
+
LOCAL cl_int
cl_program_build(cl_program p, const char *options)
{
cl_int err = CL_SUCCESS;
int i = 0;
int copyed = 0;
+ bool debugging = p->ctx->kernel_debug;
+ char *opts_debug;
if (p->ref_n > 1) {
err = CL_INVALID_OPERATION;
@@ -564,6 +591,15 @@ cl_program_build(cl_program p, const char *options)
err = CL_BUILD_PROGRAM_FAILURE;
goto error;
}
+
+ if (UNLIKELY(debugging)) {
+ opts_debug = append_option(options, OPTION_KERNEL_DEBUG);
+ if (opts_debug)
+ options = opts_debug;
+ else
+ debugging = false;
+ }
+
if (options) {
if(p->build_opts == NULL || strcmp(options, p->build_opts) != 0) {
if(p->build_opts) {
@@ -640,9 +676,13 @@ cl_program_build(cl_program p, const char *options)
}
p->is_built = 1;
p->build_status = CL_BUILD_SUCCESS;
+ if (debugging && opts_debug)
+ cl_free(opts_debug);
return CL_SUCCESS;
error:
+ if (debugging && opts_debug)
+ cl_free(opts_debug);
p->build_status = CL_BUILD_ERROR;
return err;
}
--
1.8.3.1
More information about the Beignet
mailing list