Skip to content

Commit

Permalink
bh_component: Added BH_STACK env-var to switch stack-config.
Browse files Browse the repository at this point in the history
  • Loading branch information
safl committed May 19, 2015
1 parent 323aef4 commit de39f5c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
17 changes: 10 additions & 7 deletions config.ini.in
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
#
# Stack configuration
#
[stack]
[stack_default]
type = stack
stack = node
stack_default = node
node = topological
topological = cpu

#
# Other stack configurations (for reference, experiments, testing, etc.)
#
# Rename one of "stack-configurations" below to "stack" to use it and comment out the
# one named "stack" above.
# Use the BH_STACK env-var to choose another stack configuration.
#
# Such as BH_STACK="stack_gpu"
# or
# modify the default stack configuration above ("stack_default").
#
[stack_gpu]
type = stack
stack = node
stack_gpu = node
node = topological
topological = gpu
gpu = cpu

[stack_pprint]
type = stack
stack = node
stack_pprint = node
node = topological
topological = fuseprinter
fuseprinter = pricer
pricer = cpu

[stack_cpu]
type = stack
stack = complete_reduction
stack_cpu = complete_reduction
complete_reduction = topological
topological = node
node = cpu
Expand Down
36 changes: 24 additions & 12 deletions core/bh_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ static void *get_dlsym(void *handle, const char *name,
/* Initilize children of the given component
*
* @self The component of which children will be initialized
* @from_stack Whether children should be read from stack or from component.children.
* @stack The stack configuration to use, if NULL use children-chaining.
* @return Error codes (BH_SUCCESS, BH_ERROR)
*/
bh_error bh_component_children_init(bh_component *self, int from_stack)
static bh_error component_children_init(bh_component *self, char* stack)
{
char tmp[BH_COMPONENT_NAME_SIZE];
if (from_stack) {
snprintf(tmp, BH_COMPONENT_NAME_SIZE, "stack:%s",self->name);
if (stack) {
snprintf(tmp, BH_COMPONENT_NAME_SIZE, "%s:%s", stack, self->name);
} else {
snprintf(tmp, BH_COMPONENT_NAME_SIZE, "%s:children",self->name);
snprintf(tmp, BH_COMPONENT_NAME_SIZE, "%s:children", self->name);
}
char *children_str = iniparser_getstring(self->config, tmp, NULL);
if(children_str == NULL)
Expand Down Expand Up @@ -343,17 +343,31 @@ bh_error bh_component_config_find(bh_component *self)
bh_error bh_component_init(bh_component *self, const char* name)
{
memset(self, 0, sizeof(bh_component)); // Clear component-memory
// Find configuration-file
// Find configuration-file
bh_error found_config = bh_component_config_find(self);
if (BH_SUCCESS != found_config) {
return found_config;
}

int from_stack = component_exists(self->config, "stack");
char* stack = getenv("BH_STACK"); // Get the stack from environment
int default_stack = 0;
if (NULL == stack) { // Default to "stack_default"
stack = (char*)"stack_default";
default_stack = 1;
}

int stack_exists = component_exists(self->config, stack);
if ((!default_stack) && (!stack_exists)) {
fprintf(stderr, "The requested stack configuration(%s) does not exist,"
" falling back to children-chaining.\n", stack);
}
if (!stack_exists) {
stack = NULL;
}

if (name == NULL) { // Assign name
if (from_stack) {
strcpy(self->name, "stack");
if (stack) {
strcpy(self->name, stack);
} else {
strcpy(self->name, "bridge");
}
Expand All @@ -366,9 +380,7 @@ bh_error bh_component_init(bh_component *self, const char* name)
return BH_ERROR;
}

bh_component_children_init(self, from_stack); // Initialize children

return BH_SUCCESS;
return component_children_init(self, stack); // Initialize children
}

/* Destroyes the component object.
Expand Down

0 comments on commit de39f5c

Please sign in to comment.