From 55b82750b576588883d41407bf96e3cd1adc4c62 Mon Sep 17 00:00:00 2001 From: marxin Date: Thu, 8 Oct 2015 10:06:25 +0200 Subject: [PATCH 6/9] HSA: simplify LTO partitioning and improve kernel dependencies resolution. gcc/lto/ChangeLog: 2015-10-08 Martin Liska * lto-partition.c (add_symbol_to_partition_1): Simplify a much partitioning of HSA symbols. libgomp/ChangeLog: 2015-10-08 Martin Liska * plugin/plugin-hsa.c (get_kernel_for_agent): New function. (init_single_kernel): Use it. (create_kernel_dispatch_recursive): Dtto. --- gcc/lto/lto-partition.c | 30 ------------------------------ libgomp/plugin/plugin-hsa.c | 30 ++++++++++++++++-------------- 2 files changed, 16 insertions(+), 44 deletions(-) diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c index 01a60b2..9e0b95d 100644 --- a/gcc/lto/lto-partition.c +++ b/gcc/lto/lto-partition.c @@ -196,36 +196,6 @@ add_symbol_to_partition_1 (ltrans_partition part, symtab_node *node) "adding an HSA function (host/gpu) to the " "partition: %s\n", s->binded_function->name ()); - - ipa_ref *ref; - - /* Add all parents nodes that have HSA type. */ - for (unsigned i = 0; node->iterate_referring (i, ref); i++) - { - cgraph_node *r = dyn_cast (ref->referring); - if (r && hsa_summaries->get (r)->kind != HSA_NONE) - { - add_symbol_to_partition_1 (part, r); - if (symtab->dump_file) - fprintf (symtab->dump_file, - "adding an HSA referring node: %s\n", - r->name ()); - } - } - - /* Add all children nodes that have HSA type. */ - for (unsigned i = 0; node->iterate_reference (i, ref); i++) - { - cgraph_node *r = dyn_cast (ref->referred); - if (r && hsa_summaries->get (r)->kind != HSA_NONE) - { - add_symbol_to_partition_1 (part, r); - if (symtab->dump_file) - fprintf (symtab->dump_file, - "adding an HSA referred symbol: %s\n", - r->name ()); - } - } } } } diff --git a/libgomp/plugin/plugin-hsa.c b/libgomp/plugin/plugin-hsa.c index f1c0427..ed3573f 100644 --- a/libgomp/plugin/plugin-hsa.c +++ b/libgomp/plugin/plugin-hsa.c @@ -265,14 +265,21 @@ struct hsa_context_info static struct hsa_context_info hsa_context; -/* Find kernel in MODULE by name provided in KERNEL_NAME. */ +/* Find kernel for an AGENT by name provided in KERNEL_NAME. */ static struct kernel_info * -get_kernel_in_module (struct module_info *module, const char *kernel_name) +get_kernel_for_agent (struct agent_info *agent, const char *kernel_name) { - for (unsigned i = 0; i < module->kernel_count; i++) - if (strcmp (module->kernels[i].name, kernel_name) == 0) - return &module->kernels[i]; + struct module_info *module = agent->first_module; + + while (module) + { + for (unsigned i = 0; i < module->kernel_count; i++) + if (strcmp (module->kernels[i].name, kernel_name) == 0) + return &module->kernels[i]; + + module = module->next; + } return NULL; } @@ -841,12 +848,10 @@ init_single_kernel (struct kernel_info *kernel, unsigned *max_omp_data_size) if (kernel->omp_data_size > *max_omp_data_size) *max_omp_data_size = kernel->omp_data_size; - /* FIXME: do not consider all kernels to live in a same module. */ - struct module_info *module = kernel->agent->first_module; for (unsigned i = 0; i < kernel->dependencies_count; i++) { - struct kernel_info *dependency = get_kernel_in_module - (module, kernel->dependencies[i]); + struct kernel_info *dependency = get_kernel_for_agent + (agent, kernel->dependencies[i]); if (dependency == NULL) { @@ -917,9 +922,6 @@ static struct hsa_kernel_dispatch * create_kernel_dispatch_recursive (struct kernel_info *kernel, unsigned omp_data_size) { - // TODO: find correct module - struct module_info *module = kernel->agent->first_module; - struct hsa_kernel_dispatch *shadow = create_kernel_dispatch (kernel, omp_data_size); shadow->omp_num_threads = 64; @@ -927,8 +929,8 @@ create_kernel_dispatch_recursive (struct kernel_info *kernel, for (unsigned i = 0; i < kernel->dependencies_count; i++) { - struct kernel_info *dependency = get_kernel_in_module - (module, kernel->dependencies[i]); + struct kernel_info *dependency = get_kernel_for_agent + (kernel->agent, kernel->dependencies[i]); shadow->children_dispatches[i] = create_kernel_dispatch_recursive (dependency, omp_data_size); } -- 2.5.1