Open MPI logo

Hardware Locality Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Hardware Locality Development mailing list

Subject: Re: [hwloc-devel] SWIG bindings
From: Bernd Kallies (kallies_at_[hidden])
Date: 2010-12-02 04:25:23


Hi,

I have a perl-wrapper lib for hwloc based on hwloc-1.0.2. It is written
manually because of the pointer things. However, the lib is not
complete. I use it mainly for discovering topologies. Supporting pinning
does not make sense for perl scripts to my opinion

I'm thinking about either submitting this to CPAN or to the hwloc dev
team. However, I first wanted to wait how things with hwloc 1.1 will
look, when the dust has settled somehow.

Any hints or ideas?

Attached you find the man page.

On Tue, 2010-11-30 at 11:07 -0500, Jeff Squyres wrote:
> Would anyone object if I take a whack at making some SWIG bindings for hwloc? I'm thinking specifically for perl (because that's my scripting language of choice), but I could probably be convinced to look at python as well.
>
> (this would be for 1.2 at the earliest -- definitely not for 1.1)
>

-- 
Dr. Bernd Kallies
Konrad-Zuse-Zentrum für Informationstechnik Berlin
Takustr. 7
14195 Berlin
Tel: +49-30-84185-270
Fax: +49-30-84185-311
e-mail: kallies_at_[hidden]

NAME
    Hwloc - Perl Access to Portable Hardware Locality (hwloc)

SYNOPSIS
           use Hwloc;

           # Load topology
           my $topology = hwloc_topology_init();
           die "Failed to init topology" unless $topology;
           my $rc = hwloc_topology_load($topology);
           die "Failed to load topology" if $rc;

           # Determine number of sockets and processors
           my $nProcs = hwloc_get_nbobjs_by_type($topology,HWLOC_OBJ_PU);
           die "Failed to determine number of processors" unless $nProcs;
           my $nSockets = hwloc_get_nbobjs_by_type($topology,HWLOC_OBJ_SOCKET);
           die "Failed to determine number of sockets" unless $nSockets;
           printf "Topology contains %d processors on %d sockets.\n", $nProcs, $nSockets;

           # Browse through processors, retrieve data
           my $proc = undef;
           while ($proc = hwloc_get_next_obj_by_type($topology,HWLOC_OBJ_PU,$proc)) {
             my $idx = hwloc_get_obj_data($proc,HWLOC_ObjLogicalIndex);
             my $id = hwloc_get_obj_data($proc,HWLOC_ObjOsIndex);
             my $rank = hwloc_get_obj_data($proc,HWLOC_ObjSiblingRank);
             printf "Processor %2d: os_index %2d, sibling_rank %2d\n", $idx, $id, $rank;
           }

           # Calculate distance between first and last processor
           my $firstProc = hwloc_get_obj_by_type($topology,HWLOC_OBJ_PU,0);
           my $lastProc = hwloc_get_obj_by_type($topology,HWLOC_OBJ_PU,$nProcs-1);
           my $ancestor = hwloc_get_common_ancestor_obj($topology,$firstProc,$lastProc);
           die "Failed to determine common ancestor of first and last processor" unless $ancestor;
           my $distance = hwloc_get_obj_data($firstProc,HWLOC_ObjDepth) +
                           hwloc_get_obj_data($lastProc,HWLOC_ObjDepth) -
                           2*hwloc_get_obj_data($ancestor,HWLOC_ObjDepth);
           printf "Processors %2d and %2d are %2d levels apart.\n",
                  hwloc_get_obj_data($firstProc,HWLOC_ObjOsIndex),
                  hwloc_get_obj_data($lastProc,HWLOC_ObjOsIndex),
                  $distance;

           # Destroy topology
           hwloc_topology_destroy($topology);

DESCRIPTION
    The Hwloc module provides a perl API for selected functions of the hwloc
    C API.

    Visit <http://www.open-mpi.org/projects/hwloc> for information about
    hwloc.

    The Hwloc module treats objects of C type *hwloc_topology_t* and
    *hwloc_obj_t* as perl integers. The perl value *undef* is used to
    represent the C value NULL.

    To access the properties of a *hwloc_obj_t* object, the Hwloc module
    provides the method hwloc_get_obj_data, which is not part of the hwloc C
    API.

CONSTANTS
    The following constants are exported by the Hwloc module:

  Type of topology objects
            HWLOC_OBJ_MACHINE
            HWLOC_OBJ_NODE
            HWLOC_OBJ_SOCKET
            HWLOC_OBJ_CACHE
            HWLOC_OBJ_CORE
            HWLOC_OBJ_PU
            HWLOC_OBJ_GROUP
            HWLOC_OBJ_MISC

  Topology flags
            HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM
            HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM

  Properties of topology objects
    These constants are used by the hwloc_get_obj_data method.

            HWLOC_ObjType
            HWLOC_ObjOsIndex
            HWLOC_ObjDepth
            HWLOC_ObjLogicalIndex
            HWLOC_ObjNextCousin
            HWLOC_ObjPrevCousin
            HWLOC_ObjParent
            HWLOC_ObjSiblingRank
            HWLOC_ObjNextSibling
            HWLOC_ObjPrevSibling
            HWLOC_ObjArity
            HWLOC_ObjFirstChild
            HWLOC_ObjLastChild

  Misc
            HWLOC_API_VERSION
            HWLOC_TYPE_UNORDERED
            HWLOC_TYPE_DEPTH_UNKNOWN
            HWLOC_TYPE_DEPTH_MULTIPLE
            HWLOC_CPUBIND_PROCESS
            HWLOC_CPUBIND_THREAD
            HWLOC_CPUBIND_STRICT

METHODS
    The following methods are exported:

  Create and destroy topologies
            $t = hwloc_topology_init()
            $rc = hwloc_topology_set_flags($t,$flags)
            $rc = hwloc_topology_load($t)
            hwloc_topology_destroy($t)

  Get some topology information
            $val = hwloc_topology_get_depth($t)
            $val = hwloc_topology_get_type_depth($t,$type)
            $val = hwloc_topology_get_depth_type($t,$depth)
            $val = hwloc_get_nbobjs_by_depth($t,$depth)
            $val = hwloc_get_nbobjs_by_type($t,$type)
            $val = hwloc_topology_is_thissystem($t)

  Retrieve objects and their properties
            $obj = hwloc_get_obj_by_depth($t,$depth,$idx)
            $obj = hwloc_get_obj_by_type($t,$type,$idx)
            $val = hwloc_get_obj_data($obj,$spec)

  Traversal helpers
            $obj = hwloc_get_root_obj($t)
            $obj = hwloc_get_ancestor_obj_by_depth($t,$depth,$obj)
            $obj = hwloc_get_ancestor_obj_by_type($t,$type,$obj)
            $obj = hwloc_get_next_obj_by_depth($t,$depth,$obj)
            $obj = hwloc_get_next_obj_by_type($t,$type,$obj)
            $obj = hwloc_get_pu_obj_by_os_index($t,$idx)
            $obj = hwloc_get_next_child($t,$obj,$obj)
            $obj = hwloc_get_common_ancestor_obj($t,$obj,$obj)
            $val = hwloc_obj_is_in_subtree($t,$obj,$obj)

AUTHOR
    Bernd Kallies, <kallies_at_[hidden]>

COPYRIGHT AND LICENSE
    Copyright (C) 2010 by Bernd Kallies

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself, either Perl version 5.10.1 or, at
    your option, any later version of Perl 5 you may have available.