/* *Call the function that prints the processing units hierarchy */ void hw_machine_topology (struct machine_output *ma_out) { hwloc_topology_t topo; int error; error = hwloc_topology_init(&topo); hwloc_topology_set_flags(topo, HWLOC_TOPOLOGY_FLAG_IO_DEVICES); if (!error){ hwloc_topology_load(topo); console_output[0] = '\0'; strcpy(ma_out->console_output, "\n MACHINE| Architecture organization\n\n"); print_machine(topo, hwloc_get_root_obj(topo), 0); strcat(ma_out->console_output, console_output); strcat(ma_out->console_output, "\0"); ma_out->len = strlen(ma_out->console_output); } }
int main(void) { print_machine(); printf("Integer types:\n"); print_type_size(char); print_type_size(short); print_type_size(int); print_type_size(long); print_type_size(long long); printf("\n"); print_type_size(size_t); printf("\nFloat types:\n"); print_type_size(float); print_type_size(double); print_type_size(long double); printf("\nPointer types:\n"); print_type_size(void *); print_type_size(int *); return 0; }
/* print_header Descr: Affiche à l'ecran la structure header initialisée par read_header Param: - header: Structure Ehdr correspondant au ELF header à afficher */ void print_header(Elf32_Ehdr header) { print_e_ident(header); // Magic print_class(header); // Class print_data(header); // Data print_version(header); // Version print_os_abi(header); // OS_ABI print_abi_version(header); // ABI version print_type(header); // Type print_machine(header); // Machine print_e_version(header); // Version print_entry(header); // Entry print_start_prog_headers(header); // Start of program headers print_start_section_headers(header); // Start of section headers print_flags(header); // Flags print_header_size(header); // Header size print_program_headers_size(header); // Program headers size print_program_headers_number(header); // Program headers number print_section_headers_size(header); // Section headers size print_section_headers_number(header); // Section headers number print_section_header_strtab_ndx(header); // Section header string table index }
/* *Prints the machine hierarchy *Recursive function that goes throught the machine topology object *an group them into hierarchical groups * topology: the HWLOC object * obj: the current object in the topology * depth: the horizontal level in the machine topology */ void print_machine(hwloc_topology_t topo, hwloc_obj_t obj, int depth) { char string[256], out_string[256]; unsigned i,arity; int *devIds,devId,countDev; if(obj->type == HWLOC_OBJ_SOCKET || obj->type == HWLOC_OBJ_MACHINE ){ hwloc_obj_snprintf(string, sizeof(string), topology, obj, "#", 0); sprintf(out_string,"%*s%s\n", depth, "", string); strcat(console_output,out_string); } else if (obj->type == HWLOC_OBJ_NODE){ hwloc_obj_snprintf(string, sizeof(string), topology, obj, "#", 0); sprintf(out_string,"%*s%s\n", depth, "", string); strcat(console_output,out_string); //if the machine has shared GPUs #if defined (__DBCSR_ACC) || defined (__PW_CUDA) if ((local_topo->ngpus > 0) && (local_topo->ngpus < local_topo->ncores)){ ma_get_nDevcu(obj->logical_index, &countDev); devIds = malloc (countDev*sizeof(int)); ma_get_cu(obj->logical_index, devIds); strcat(console_output," Shared GPUS: "); for (i = 0; i<countDev; i++){ devId = devIds[i]; sprintf(out_string,"#%d ", devId); strcat(console_output,out_string);} strcat(console_output,"\n"); } #endif } else { hwloc_obj_snprintf(string, sizeof(string), topology, obj, "#", 0); if(obj->type == HWLOC_OBJ_PU ) { #if defined (__DBCSR_ACC) || defined (__PW_CUDA) sprintf(out_string,"%*s%s\t", depth, "", string); strcat(console_output,out_string); if (local_topo->ngpus > 0 && local_topo->ngpus == local_topo->ncores){ ma_get_core_cu(obj->logical_index, &devId); strcat(console_output," GPU: "); sprintf(out_string,"%d ", devId); strcat(console_output,out_string);} strcat(console_output,"\n"); #else sprintf(out_string,"%*s%s\n", depth, "", string); strcat(console_output,out_string); #endif } else if (obj->type == HWLOC_OBJ_CACHE && obj->arity>1 ){ hwloc_obj_type_snprintf(string, sizeof(string), obj, 0); sprintf(out_string,"%*s%s", depth, "", string); strcat(console_output,out_string); sprintf(out_string," (%dMB)\n", obj->attr->cache.size/(1024*1024)); strcat(console_output,out_string); } else if (obj->type == HWLOC_OBJ_OS_DEVICE || obj->type == HWLOC_OBJ_PCI_DEVICE || obj->type == HWLOC_OBJ_BRIDGE){ if(obj->attr->osdev.type == HWLOC_OBJ_OSDEV_NETWORK ){ sprintf(out_string,"%*s%s\n", depth, "--", "Network Card"); strcat(console_output,out_string);} } else if (obj->type == HWLOC_OBJ_CORE) { char number[33]; strcpy(string,"Core#"); sprintf(number,"%d",obj->logical_index); strcat(string,number); sprintf(out_string,"%*s%s\t", depth, "", string); strcat(console_output,out_string); } else { sprintf(out_string,"%*s%s\t", depth, "", string); strcat(console_output,out_string); } } if (obj->type != HWLOC_OBJ_PU) {//it is not a PU if((obj->first_child && obj->first_child->type == HWLOC_OBJ_PU)) arity = 1; //number of children else arity = obj->arity; for (i = 0; i < arity; i++) print_machine(topo, obj->children[i],depth+1); } }