Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: update with module and fix empty struct #2

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

vsoch
Copy link

@vsoch vsoch commented Feb 28, 2024

Problem: the current version does not have a go module, and the build / run will fail with recent versions of go (cgo) that do not allow creating an empty struct. This is an attempt to fix that. I will need to test it to see if it actually works. I am also adding GitHub CI (to run go test) along with a VSCode developer container environment that has hwloc ready to go for easier development.

I'm going to do a quick test with my branch here (via a PR that specifies a different module path) and can report back.

Problem: the current version does not have a go module,
and the build / run will fail with recent versions of
go (cgo) that do not allow creating an empty struct.
This is an attempt to fix that. I will need to test it
to see if it actually works. I am also adding GitHub CI
(to run go test) along with a VSCode developer container
environment that has hwloc ready to go for easier development.

Signed-off-by: vsoch <[email protected]>
@vsoch
Copy link
Author

vsoch commented Feb 28, 2024

Ah I think I see the issues you were probably running into? Go doesn't like the static bit for a module:

/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

I tried building hwloc as a non static library, that doesn't work either.

make[3]: Entering directory '/opt/hwloc/utils/hwloc'
  CCLD     hwloc-annotate
/usr/bin/ld: attempted static link of dynamic object `/opt/hwloc/hwloc/.libs/libhwloc.so'
collect2: error: ld returned 1 exit status

I'll ping some of my colleagues and see if they have any ideas. We wanted to use this for a compatibility checking tool for applications and containers (for OCI) but seems like it might be the wrong tool if it's impossible to use.

@c0mm4nd
Copy link
Owner

c0mm4nd commented Feb 29, 2024

Thanks for your great PR.

getaddrinfo warning is not from this lib or golang favor, it's from glibc xmrig/xmrig#238 (comment).

If you want to use libhwloc as a shared lib, suggest removing the lines like //#cgo LDFLAGS: -static -static-libgcc before go build.

* test: building without libgcc

Signed-off-by: vsoch <[email protected]>
@vsoch
Copy link
Author

vsoch commented Feb 29, 2024

That worked! I've updated the PR here. Quick question for you - what is a "hello world" example for using this? I've been trying to do a basic init and then "print something out I can see" - my first effort the print segfaulted, and then I followed a pattern in a test and it doesn't segfault (but I don't see anything). I'm new to using hwloc outside of the command line tools so apologies for my naivete. Here is what I am testing:

	topo, err := hwloc.NewTopology()
	if err != nil {
		return info, err
	}
	err = topo.Load()
	if err != nil {
		return info, err
	}
	nodeSet := topo.HwlocGetNUMANodeObjByOSIndex(0)
	topo.HwlocSetMemBind(nodeSet, hwloc.HwlocMemBindBind, hwloc.HwlocMemBindThread|hwloc.HwlocMemBindByNodeSet)
	nodes, err := nodeSet.Values()
	if err != nil {
		return info, err
	}
	for _, node := range nodes {
		fmt.Println(node)
	}

I'm mostly looking to print out metadata / see what I have to work with.

@c0mm4nd
Copy link
Owner

c0mm4nd commented Mar 1, 2024

To check the result of topo.HwlocSetMemBind, you can use HWLOC_DECLSPEC int hwloc_get_membind(hwloc_topology_t topology, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags); to get the policy (not implemented in go yet, but its easy).

@vsoch
Copy link
Author

vsoch commented Mar 1, 2024

I'm generally interested in getting the equivalent output that I might get for lstopo or in the xml file generated - I'm not a C programmer so the "it's easy" part is probably not applicable here! 😆 Do you have examples / know someone that has used your library that might help me get started?

@c0mm4nd
Copy link
Owner

c0mm4nd commented Mar 17, 2024

Sorry for replying late. This repo was used to enable NUMA support on GxMiner.

@vsoch
Copy link
Author

vsoch commented Mar 17, 2024

No worries, and thanks! I will likely take a look in the next few weeks (just very busy this week).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants