示例#1
0
/*
 * os_index is unique in a given layer of the hierarchy (it seems), but
 * definitely not unique across all hwloc objects.
 */
static void print_hwloc_obj(hwloc_obj_t obj, int indent) {
    for (int i = 0; i < indent; i++) {
        printf("|  ");
    }
    /*
     * Unforunately, it seems that on many platforms hwloc does not provide
     * distances between child devices (i.e. distances_count == 0).
     */
    printf("obj %u (type=%s , depth=%d, %d child/children, parent=%u, name=%s, "
            "distance count=%u, infos_count=%u)\n", obj->os_index, str_for_type(obj->type),
            obj->depth, obj->arity, obj->parent ? obj->parent->os_index : 0,
            obj->name ? obj->name : "", obj->distances_count, obj->infos_count);
    if (obj->infos_count > 0) {
        for (int i = 0; i < indent + 2; i++) {
            printf("--");
        }
        struct hwloc_obj_info_s * infos = obj->infos;
        for (int i = 0; i < obj->infos_count; i++) {
            if (i != 0) printf(", ");
            printf("%s=%s", infos[i].name, infos[i].value);
        }
        printf("\n");
    }

    for (int i = 0; i < obj->arity; i++) {
        print_hwloc_obj(obj->children[i], indent + 1);
    }
}
示例#2
0
static void write_hpt_tree(std::ofstream &output, hwloc_obj_t obj, int indent) {
#ifdef VERBOSE
    std::cout << "obj " << obj->os_index << " (type=" <<
        std::string(str_for_type(obj->type)) << ", memory=" <<
        is_memory_place(obj) << ", cache=" << is_cache_place(obj) <<
        ", worker=" << is_cpu_worker(obj) << ", nvgpu=" <<
        is_nvgpu_place(obj) << std::endl;
#endif

    if (is_memory_place(obj)) {
        write_indent(output, indent);
        output << "<place num=\"1\" type=\"mem\">" << std::endl;
        recur_on_children(output, obj, indent + 1);
        write_indent(output, indent);
        output << "</place>" << std::endl;
    } else if (is_cache_place(obj)) {
        write_indent(output, indent);
        output << "<place num=\"1\" type=\"cache\">" << std::endl;
        recur_on_children(output, obj, indent + 1);
        write_indent(output, indent);
        output << "</place>" << std::endl;
    } else if (is_cpu_worker(obj)) {
        assert(obj->arity == 0);
        write_indent(output, indent);
        output << "<worker num=\"1\"/>" << std::endl;
    } else if (is_nvgpu_place(obj)) {
        write_indent(output, indent);
        output << "<place num=\"1\" type=\"nvgpu\" info=\"" <<
            std::string(get_hwloc_info(obj, "GPUVendor")) << ", " <<
            std::string(get_hwloc_info(obj, "GPUModel")) << "\">" << std::endl;
        recur_on_children(output, obj, indent + 1);
        write_indent(output, indent);
        output << "</place>" << std::endl;
    } else {
        // Just continue down the tree, ignoring whatever the current node is
        recur_on_children(output, obj, indent);
    }
}