Commit a5a978a9 authored by Thomas Applencourt's avatar Thomas Applencourt
Browse files

Add namespace

parent 71be6239
Pipeline #13012 failed with stage
......@@ -22,17 +22,17 @@
// member_count, member_count == 1 ? "" : "s");
//}
struct opencl_event_callbacks * opencl_create_event_callbacks(const char *name) {
intptr_t mem = (intptr_t)calloc(1, sizeof(struct opencl_event_callbacks) + strlen(name) + 1);
struct opencl_event_callbacks * callbacks = (struct opencl_event_callbacks *)mem;
callbacks->name = (const char *)(mem + sizeof(struct opencl_event_callbacks));
struct babeltrace_cl_event_callbacks * opencl_create_event_callbacks(const char *name) {
intptr_t mem = (intptr_t)calloc(1, sizeof(struct babeltrace_cl_event_callbacks) + strlen(name) + 1);
struct babeltrace_cl_event_callbacks * callbacks = (struct babeltrace_cl_event_callbacks *)mem;
callbacks->name = (const char *)(mem + sizeof(struct babeltrace_cl_event_callbacks));
strcpy((char *)(callbacks->name), name);
utarray_new(callbacks->callbacks, &ut_ptr_icd);
return callbacks;
}
void opencl_register_dispatcher(struct opencl_dispatch *opencl_dispatch, const char *name, opencl_dispatcher_t *dispatcher) {
struct opencl_event_callbacks *callbacks = NULL;
void babeltrace_cl_register_dispatcher(struct babeltrace_cl_dispatch *opencl_dispatch, const char *name, babeltrace_cl_dispatcher_t *dispatcher) {
struct babeltrace_cl_event_callbacks *callbacks = NULL;
HASH_FIND_STR(opencl_dispatch->event_callbacks, name, callbacks);
if (!callbacks) {
callbacks = opencl_create_event_callbacks(name);
......@@ -41,8 +41,8 @@ void opencl_register_dispatcher(struct opencl_dispatch *opencl_dispatch, const c
callbacks->dispatcher = dispatcher;
}
void opencl_register_callback(struct opencl_dispatch *opencl_dispatch, const char *name, void *func) {
struct opencl_event_callbacks *callbacks;
void babeltrace_cl_register_callback(struct babeltrace_cl_dispatch *opencl_dispatch, const char *name, void *func) {
struct babeltrace_cl_event_callbacks *callbacks;
HASH_FIND_STR(opencl_dispatch->event_callbacks, name, callbacks);
if (!callbacks) {
callbacks = opencl_create_event_callbacks(name);
......@@ -62,7 +62,7 @@ bt_component_class_initialize_method_status opencl_dispatch_initialize(
const bt_value *params, void *initialize_method_data)
{
/* Allocate a private data structure */
struct opencl_dispatch *opencl_dispatch = calloc(1, sizeof(struct opencl_dispatch));
struct babeltrace_cl_dispatch *opencl_dispatch = calloc(1, sizeof(struct babeltrace_cl_dispatch));
/* Set the component's user data to our private data structure */
bt_self_component_set_data(
......@@ -80,7 +80,7 @@ bt_component_class_initialize_method_status opencl_dispatch_initialize(
bt_self_component_sink_add_input_port(self_component_sink,
"in", NULL, NULL);
init_dispatchers(opencl_dispatch);
init_babeltrace_cl_dispatchers(opencl_dispatch);
return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
}
......@@ -91,15 +91,15 @@ static
void opencl_dispatch_finalize(bt_self_component_sink *self_component_sink)
{
/* Retrieve our private data from the component's user data */
struct opencl_dispatch *opencl_dispatch = bt_self_component_get_data(
struct babeltrace_cl_dispatch *opencl_dispatch = bt_self_component_get_data(
bt_self_component_sink_as_self_component(self_component_sink));
struct opencl_callbacks *s, *tmp;
struct babeltrace_cl_callbacks *s, *tmp;
HASH_ITER(hh, opencl_dispatch->callbacks, s, tmp) {
HASH_DEL(opencl_dispatch->callbacks, s);
free(s);
}
struct opencl_event_callbacks *s2, *tmp2;
struct babeltrace_cl_event_callbacks *s2, *tmp2;
HASH_ITER(hh, opencl_dispatch->event_callbacks, s2, tmp2) {
HASH_DEL(opencl_dispatch->event_callbacks, s2);
utarray_free(s2->callbacks);
......@@ -120,7 +120,7 @@ bt_component_class_sink_graph_is_configured_method_status
opencl_dispatch_graph_is_configured(bt_self_component_sink *self_component_sink)
{
/* Retrieve our private data from the component's user data */
struct opencl_dispatch *opencl_dispatch = bt_self_component_get_data(
struct babeltrace_cl_dispatch *opencl_dispatch = bt_self_component_get_data(
bt_self_component_sink_as_self_component(self_component_sink));
/* Borrow our unique port */
......@@ -147,7 +147,7 @@ bt_component_class_sink_consume_method_status opencl_dispatch_consume(
BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
/* Retrieve our private data from the component's user data */
struct opencl_dispatch *opencl_dispatch = bt_self_component_get_data(
struct babeltrace_cl_dispatch *opencl_dispatch = bt_self_component_get_data(
bt_self_component_sink_as_self_component(self_component_sink));
/* Consume a batch of messages from the upstream message iterator */
......@@ -183,17 +183,17 @@ bt_component_class_sink_consume_method_status opencl_dispatch_consume(
if (bt_message_get_type(message) == BT_MESSAGE_TYPE_EVENT) {
const bt_event *event = bt_message_event_borrow_event_const(message);
const bt_event_class *event_class = bt_event_borrow_class_const(event);
struct opencl_callbacks *callbacks = NULL;
struct babeltrace_cl_callbacks *callbacks = NULL;
const char * class_name = bt_event_class_get_name(event_class);
HASH_FIND_STR(opencl_dispatch->callbacks, class_name, callbacks);
if (!callbacks) {
const size_t class_name_sz = strlen(class_name);
callbacks = (struct opencl_callbacks *)calloc(1, sizeof(struct opencl_callbacks) + class_name_sz + 1);
callbacks = (struct babeltrace_cl_callbacks *)calloc(1, sizeof(struct babeltrace_cl_callbacks) + class_name_sz + 1);
callbacks->name = (const char *)callbacks + class_name_sz;
strncpy((char *)(callbacks->name), class_name, class_name_sz + 1);
HASH_ADD_KEYPTR(hh, opencl_dispatch->callbacks, class_name, class_name_sz, callbacks);
struct opencl_event_callbacks *event_callbacks = NULL;
struct babeltrace_cl_event_callbacks *event_callbacks = NULL;
HASH_FIND_STR(opencl_dispatch->event_callbacks, class_name, event_callbacks);
if (event_callbacks) {
callbacks->dispatcher = event_callbacks->dispatcher;
......
......@@ -15,50 +15,50 @@
extern "C" {
#endif
struct opencl_dispatch;
struct opencl_callbacks;
struct babeltrace_cl_dispatch;
struct babeltrace_cl_callbacks;
extern void init_dispatchers(struct opencl_dispatch *opencl_dispatch);
extern void init_babeltrace_cl_dispatchers(struct babeltrace_cl_dispatch *dispatch);
typedef void (opencl_dispatcher_t)
(struct opencl_dispatch *opencl_dispatch,
struct opencl_callbacks *callbacks,
typedef void (babeltrace_cl_dispatcher_t)
(struct babeltrace_cl_dispatch *dispatch,
struct babeltrace_cl_callbacks *callbacks,
const bt_event *message,
const bt_clock_snapshot *clock);
struct opencl_callbacks {
struct babeltrace_cl_callbacks {
const char *name;
opencl_dispatcher_t *dispatcher;
babeltrace_cl_dispatcher_t *dispatcher;
UT_array *callbacks;
UT_hash_handle hh;
};
struct opencl_event_callbacks {
struct babeltrace_cl_event_callbacks {
const char *name;
opencl_dispatcher_t *dispatcher;
babeltrace_cl_dispatcher_t *dispatcher;
UT_array *callbacks;
UT_hash_handle hh;
};
/* Sink component's private data */
struct opencl_dispatch {
struct babeltrace_cl_dispatch {
/* Upstream message iterator (owned by this) */
bt_message_iterator *message_iterator;
/* Hash table */
struct opencl_callbacks *callbacks;
struct babeltrace_cl_callbacks *callbacks;
/* Hash table by name */
struct opencl_event_callbacks *event_callbacks;
struct babeltrace_cl_event_callbacks *event_callbacks;
};
extern void
opencl_register_dispatcher(struct opencl_dispatch *opencl_dispatch,
babeltrace_cl_register_dispatcher(struct babeltrace_cl_dispatch *dispatch,
const char *name,
opencl_dispatcher_t *dispatcher);
babeltrace_cl_dispatcher_t *dispatcher);
extern void
opencl_register_callback(struct opencl_dispatch *opencl_dispatch,
babeltrace_cl_register_callback(struct babeltrace_cl_dispatch *dispatch,
const char *name,
void *func);
#ifdef __cplusplus
......@@ -66,3 +66,4 @@ opencl_register_callback(struct opencl_dispatch *opencl_dispatch,
#endif
#endif
......@@ -7,17 +7,17 @@ const bt_value *display_mode;
const bt_value *test_type_value;
<% end %>
struct opencl_event_callbacks * opencl_create_event_callbacks(const char *name) {
intptr_t mem = (intptr_t)calloc(1, sizeof(struct opencl_event_callbacks) + strlen(name) + 1);
struct opencl_event_callbacks * callbacks = (struct opencl_event_callbacks *)mem;
callbacks->name = (const char *)(mem + sizeof(struct opencl_event_callbacks));
struct babeltrace_cl_event_callbacks * opencl_create_event_callbacks(const char *name) {
intptr_t mem = (intptr_t)calloc(1, sizeof(struct babeltrace_cl_event_callbacks) + strlen(name) + 1);
struct babeltrace_cl_event_callbacks * callbacks = (struct babeltrace_cl_event_callbacks *)mem;
callbacks->name = (const char *)(mem + sizeof(struct babeltrace_cl_event_callbacks));
strcpy((char *)(callbacks->name), name);
utarray_new(callbacks->callbacks, &ut_ptr_icd);
return callbacks;
}
void opencl_register_dispatcher(struct opencl_dispatch *opencl_dispatch, const char *name, opencl_dispatcher_t *dispatcher) {
struct opencl_event_callbacks *callbacks = NULL;
void babeltrace_cl_register_dispatcher(struct babeltrace_cl_dispatch *opencl_dispatch, const char *name, babeltrace_cl_dispatcher_t *dispatcher) {
struct babeltrace_cl_event_callbacks *callbacks = NULL;
HASH_FIND_STR(opencl_dispatch->event_callbacks, name, callbacks);
if (!callbacks) {
callbacks = opencl_create_event_callbacks(name);
......@@ -26,8 +26,8 @@ void opencl_register_dispatcher(struct opencl_dispatch *opencl_dispatch, const c
callbacks->dispatcher = dispatcher;
}
void opencl_register_callback(struct opencl_dispatch *opencl_dispatch, const char *name, void *func) {
struct opencl_event_callbacks *callbacks;
void babeltrace_cl_register_callback(struct babeltrace_cl_dispatch *opencl_dispatch, const char *name, void *func) {
struct babeltrace_cl_event_callbacks *callbacks;
HASH_FIND_STR(opencl_dispatch->event_callbacks, name, callbacks);
if (!callbacks) {
callbacks = opencl_create_event_callbacks(name);
......@@ -55,7 +55,7 @@ bt_component_class_initialize_method_status opencl_dispatch_initialize(
<% end %>
/* Allocate a private data structure */
struct opencl_dispatch *opencl_dispatch = calloc(1, sizeof(struct opencl_dispatch));
struct babeltrace_cl_dispatch *opencl_dispatch = calloc(1, sizeof(struct babeltrace_cl_dispatch));
/* Set the component's user data to our private data structure */
bt_self_component_set_data(
......@@ -72,9 +72,8 @@ bt_component_class_initialize_method_status opencl_dispatch_initialize(
*/
bt_self_component_sink_add_input_port(self_component_sink,
"in", NULL, NULL);
init_dispatchers(opencl_dispatch);
init_callbacks(opencl_dispatch);
init_babeltrace_cl_dispatchers(opencl_dispatch);
init_babeltrace_cl_callbacks(opencl_dispatch);
return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
}
......@@ -85,22 +84,23 @@ static
void opencl_dispatch_finalize(bt_self_component_sink *self_component_sink)
{
finalize_callbacks();
finalize_babeltrace_cl_callbacks();
/* Retrieve our private data from the component's user data */
struct opencl_dispatch *opencl_dispatch = bt_self_component_get_data(
struct babeltrace_cl_dispatch *opencl_dispatch = bt_self_component_get_data(
bt_self_component_sink_as_self_component(self_component_sink));
struct opencl_callbacks *s, *tmp;
struct babeltrace_cl_callbacks *s, *tmp;
HASH_ITER(hh, opencl_dispatch->callbacks, s, tmp) {
HASH_DEL(opencl_dispatch->callbacks, s);
free(s);
}
struct opencl_event_callbacks *s2, *tmp2;
struct babeltrace_cl_event_callbacks *s2, *tmp2;
HASH_ITER(hh, opencl_dispatch->event_callbacks, s2, tmp2) {
HASH_DEL(opencl_dispatch->event_callbacks, s2);
utarray_free(s2->callbacks);
free(s2);
}
<% if $sink_type == 'testing' %>
bt_value_put_ref(test_type_value);
<% elsif $sink_type == 'production' %>
......@@ -109,7 +109,6 @@ void opencl_dispatch_finalize(bt_self_component_sink *self_component_sink)
/* Free the allocated structure */
free(opencl_dispatch);
}
/*
* Called when the trace processing graph containing the sink component
* is configured.
......@@ -121,7 +120,7 @@ bt_component_class_sink_graph_is_configured_method_status
opencl_dispatch_graph_is_configured(bt_self_component_sink *self_component_sink)
{
/* Retrieve our private data from the component's user data */
struct opencl_dispatch *opencl_dispatch = bt_self_component_get_data(
struct babeltrace_cl_dispatch *opencl_dispatch = bt_self_component_get_data(
bt_self_component_sink_as_self_component(self_component_sink));
/* Borrow our unique port */
......@@ -148,7 +147,7 @@ bt_component_class_sink_consume_method_status opencl_dispatch_consume(
BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
/* Retrieve our private data from the component's user data */
struct opencl_dispatch *opencl_dispatch = bt_self_component_get_data(
struct babeltrace_cl_dispatch *opencl_dispatch = bt_self_component_get_data(
bt_self_component_sink_as_self_component(self_component_sink));
/* Consume a batch of messages from the upstream message iterator */
......@@ -184,17 +183,17 @@ bt_component_class_sink_consume_method_status opencl_dispatch_consume(
if (bt_message_get_type(message) == BT_MESSAGE_TYPE_EVENT) {
const bt_event *event = bt_message_event_borrow_event_const(message);
const bt_event_class *event_class = bt_event_borrow_class_const(event);
struct opencl_callbacks *callbacks = NULL;
struct babeltrace_cl_callbacks *callbacks = NULL;
const char * class_name = bt_event_class_get_name(event_class);
HASH_FIND_STR(opencl_dispatch->callbacks, class_name, callbacks);
if (!callbacks) {
const size_t class_name_sz = strlen(class_name);
callbacks = (struct opencl_callbacks *)calloc(1, sizeof(struct opencl_callbacks) + class_name_sz + 1);
callbacks = (struct babeltrace_cl_callbacks *)calloc(1, sizeof(struct babeltrace_cl_callbacks) + class_name_sz + 1);
callbacks->name = (const char *)callbacks + class_name_sz;
strncpy((char *)(callbacks->name), class_name, class_name_sz + 1);
HASH_ADD_KEYPTR(hh, opencl_dispatch->callbacks, class_name, class_name_sz, callbacks);
struct opencl_event_callbacks *event_callbacks = NULL;
struct babeltrace_cl_event_callbacks *event_callbacks = NULL;
HASH_FIND_STR(opencl_dispatch->event_callbacks, class_name, event_callbacks);
if (event_callbacks) {
callbacks->dispatcher = event_callbacks->dispatcher;
......
......@@ -197,9 +197,9 @@ static void clprof_<%= dbt_event.name %>_callback(
%>
void init_callbacks(struct opencl_dispatch *opencl_dispatch) {
void init_babeltrace_cl_callbacks(struct babeltrace_cl_dispatch *opencl_dispatch) {
<% $dbt_events.each do | dbt_event| %>
opencl_register_callback(opencl_dispatch, "<%= dbt_event.name_unsanitized %>", (void *) &clprof_<%= dbt_event.name %>_callback);
babeltrace_cl_register_callback(opencl_dispatch, "<%= dbt_event.name_unsanitized %>", (void *) &clprof_<%= dbt_event.name %>_callback);
<% end %>
}
......@@ -210,7 +210,7 @@ void init_callbacks(struct opencl_dispatch *opencl_dispatch) {
%>
void finalize_callbacks() {
void finalize_babeltrace_cl_callbacks() {
<% if $sink_type == 'testing' %>
std::string test_path {bt_value_string_get(test_type_value)};
<% $l_test.each do | test | %>
......
......@@ -6,9 +6,9 @@
extern "C" {
#endif
extern void
init_callbacks(struct opencl_dispatch *opencl_dispatch);
init_babeltrace_cl_callbacks(struct babeltrace_cl_dispatch *opencl_dispatch);
extern void
finalize_callbacks();
finalize_babeltrace_cl_callbacks();
<% if $sink_type == 'testing' %>
extern const bt_value *test_type_value;
<% elsif $sink_type == 'production' %>
......
require 'yaml'
if ARGV.empty?
namespace = "babeltrace_cl"
else
namespace = ARGV[0]
end
opencl_babeltrace_model = YAML::load_file("opencl_babeltrace_model.yaml")
puts <<EOF
#ifndef _HEADER_CALLBACKS_H
#define _HEADER_CALLBACKS_H
#ifndef #{namespace.upcase}_HEADER_CALLBACKS_H
#define #{namespace.upcase}_HEADER_CALLBACKS_H
#define CL_TARGET_OPENCL_VERSION 300
#define CL_USE_DEPRECATED_OPENCL_1_0_APIS
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
......@@ -17,7 +24,7 @@ puts <<EOF
#include <CL/cl_ext_intel.h>
#include "tracer_opencl.h"
#include "babeltrace_cl.h"
#include "#{namespace}.h"
EOF
......@@ -30,7 +37,7 @@ opencl_babeltrace_model[:event_classes].each { |klass|
decls.push [f[:cast_type], f[:name]]
}
puts <<EOF
typedef void (#{name.gsub(":","_")}_cb)(
typedef void (#{namespace}_#{name.gsub(":","_")}_cb)(
#{(["const bt_event *bt_evt", "const bt_clock_snapshot *bt_clock"]+
decls.collect { |t, n| "#{t} #{n}" }).join(",\n ")});
......
require 'yaml'
if ARGV.empty?
namespace = "babeltrace_cl"
else
namespace = ARGV[0]
end
opencl_babeltrace_model = YAML::load_file("opencl_babeltrace_model.yaml")
puts <<EOF
#include "babeltrace_cl.h"
#include "babeltrace_cl_callbacks.h"
#include "#{namespace}.h"
#include "#{namespace}_callbacks.h"
EOF
......@@ -113,8 +121,8 @@ opencl_babeltrace_model[:event_classes].each { |klass|
puts <<EOF
static void
#{name.gsub(":","_")}_dispatcher(
struct opencl_dispatch *opencl_dispatch,
struct opencl_callbacks *callbacks,
struct #{namespace}_dispatch *dispatch,
struct #{namespace}_callbacks *callbacks,
const bt_event *bt_evt,
const bt_clock_snapshot *bt_clock) {
#{decls.each.collect { |f| "#{f[0]} #{f[1]}" }.join(";\n ")};
......@@ -123,7 +131,7 @@ print_field_members_access(fields)
puts <<EOF
void **_p = NULL;
while( (_p = utarray_next(callbacks->callbacks, _p)) ) {
((#{name.gsub(":","_")}_cb *)*_p)(
((#{namespace}_#{name.gsub(":","_")}_cb *)*_p)(
#{(["bt_evt", "bt_clock"] + decls.collect { |f| f[1] }).join(",\n ")});
}
EOF
......@@ -143,12 +151,12 @@ EOF
}
puts <<EOF
void init_dispatchers(struct opencl_dispatch *opencl_dispatch) {
void init_#{namespace}_dispatchers(struct #{namespace}_dispatch *dispatch) {
EOF
opencl_babeltrace_model[:event_classes].each { |klass|
name = klass[:name]
puts <<EOF
opencl_register_dispatcher(opencl_dispatch, "#{name}", &#{name.gsub(":","_")}_dispatcher);
#{namespace}_register_dispatcher(dispatch, "#{name}", &#{name.gsub(":","_")}_dispatcher);
EOF
}
puts <<EOF
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment