Skip to content

Commit

Permalink
make abstract tree interface an extension
Browse files Browse the repository at this point in the history
  • Loading branch information
JBlaschke committed Dec 31, 2023
1 parent 8d5d31c commit 80c8e50
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
14 changes: 12 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ authors = ["Erik Schnetter <[email protected]>"]
version = "3.1.1"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Hwloc_jll = "e33a78d0-f292-5ffc-b300-72abe9b543c8"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[weakdeps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

[compat]
CEnum = "0.4"
Hwloc_jll = "2.8"
julia = "1.6"
AbstractTrees = "0.4.4"

[extras]
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

[extensions]
# * name of extension to the left
# * extension dependencies required to load the extension to the right
# * use a list for multiple extension dependencies
HwlocTrees = "AbstractTrees"

[targets]
test = ["Test", "CpuId"]
test = ["Test", "CpuId", "AbstractTrees"]
12 changes: 10 additions & 2 deletions src/tree.jl → ext/HwlocTrees.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module HwlocTrees

using Hwloc, Printf
import AbstractTrees

mutable struct HwlocTreeNode{T}
object::Object
object::Hwloc.Object
type::Symbol
tag::Union{Nothing, T}

Expand All @@ -10,7 +13,7 @@ mutable struct HwlocTreeNode{T}
memory_children::Vector{HwlocTreeNode{T}}
io_children::Vector{HwlocTreeNode{T}}

function HwlocTreeNode{T}(obj::Object; parent=nothing, type=nothing) where {T}
function HwlocTreeNode{T}(obj::Hwloc.Object; parent=nothing, type=nothing) where {T}
this = new{T}(obj, obj.type_, nothing, parent)

this.children = HwlocTreeNode{T}.(obj.children; parent=this)
Expand All @@ -21,6 +24,10 @@ mutable struct HwlocTreeNode{T}
end
end

function AbstractTrees.children(node::Hwloc.Object)
HwlocTreeNode{UInt8}(node)
end

function AbstractTrees.children(node::HwlocTreeNode)
tuple(node.children..., node.memory_children..., node.io_children...)
end
Expand Down Expand Up @@ -81,3 +88,4 @@ function tag_subtree!(tree_node, val)
n.tag = val
end
end
end
2 changes: 0 additions & 2 deletions src/Hwloc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ include("libhwloc.jl")
include("libhwloc_extensions.jl")
include("lowlevel_api.jl")
include("highlevel_api.jl")
include("tree.jl")

export topology, gettopology, topology_info, getinfo, print_topology, topology_graphical
export num_physical_cores, num_virtual_cores, num_packages, num_numa_nodes
export cachesize, cachelinesize
export hwloc_typeof, hwloc_isa, collectobjects
export HwlocTreeNode

const machine_topology = Ref{Object}()

Expand Down

0 comments on commit 80c8e50

Please sign in to comment.