Skip to content

Commit

Permalink
fix namespace (+64 squashed commit)
Browse files Browse the repository at this point in the history
Squashed commit:

[cd6d100] update- remove bazel conf files- add the bazel suggestions into Readme- remove hwloc submodule- add tutorial for ubuntu windows and arch- use shared lib when not on windows

[8842e9b] Create LICENSE

for pkg.go.dev

[a7063d5] Update README.md

[f42f17b] Update README.md

[e78c8a2] add hwloc.h for go vet

[2cc4a34] rm go.mod for git submodule import method

[17b0f7a] Update README.md

[3744ae7] fmt

[fa9a5fc] +windows

[0f803b0] update

[4998f64] enable static

[afd9676] disable libxml2

[490e128] libxml2

[ad3cb03] handling internal error

[2a1fb03] handling internal error

[f8a4e17] sudo

[8160a70] update

[d9b542d] update

[ffe55fb] update

[38b2081] update

[3f298b5] static

[3238a52] update

[6e4d10c] update

[4374978] update

[00df8b3] the last try

[dc6f999] test sudo make install

[bc39acf] bugfix

[bc1070a] bugfix

[f060729] bugfix

[8bc7f9b] bugfix

[3408d60] update travis

[cf61857] update travis

[1eb3859] update travis

[ff7f9cc] edit submodule

[3338157] remove unnecessary folders

[8ed22f4] update travis

[ccab984] tidy go mod

[3649653] Refactoring the code for go mod and add 2 func for numa

[edc5866] fix object's Parent issue

[e571241] add io child devices into object

[250a839] rename org to gpucloud

[7d81e04] update README.md for gohwloc on installation

[dafe433] rename hwloc-ls to gpu

[8a95ca9] add more functions

[f946fda] add type filter function

[e2b77f4] add cuda info into cli

[9b4af4a] add bitmap string

[089eeff] add object parent and cpuset

[9fe653c] add build status of travis-ci

[c52897c] limit the go version bigger than 1.10

[bd5b0b4] add vendor

[a447503] sudo make install

[fc226f2] update git submodules

[af2a08f] add .travis.yml

[75336d2] set HwlocObject based on hwloc_obj_t

[fbc25e2] add bitmap

[e1173a6] add HwlocCPUSet

[caacd03] add cpubind, membind

[cdd0320] add bitmap

[e0403ff] update object function, add gpu locationw

[ff34419] delete gohwloc.go and main.go

[21a74f9] change org name

[85ca19d] remote _output dir

[d3e5bdf] init commit
  • Loading branch information
carmark authored and c0mm4nd committed Sep 12, 2023
1 parent 5a90fcc commit 0e7d07c
Show file tree
Hide file tree
Showing 20 changed files with 3,676 additions and 4 deletions.
54 changes: 54 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Autoconf/Automake generated files
aclocal.m4
.deps
autom4te.cache
Makefile.in
ar-lib
compile
config.log
config.status
configure
depcomp
install-sh
missing
config.guess
config.sub

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof

# intellij idea configure
.idea
*.out
*.bak
*.dat
_output/

.DS_Store
*.pem
*.key
*.sqlite
cmd/client/grpccli
db/
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sudo: required
language: go

go:
- "1.13"

before_install:
- git clone https://github.com/open-mpi/hwloc
- cd hwloc
- ./autogen.sh
- ./configure --enable-static --disable-shared LDFLAGS="-static"
- make LDFLAGS=-all-static
- sudo make install
- sudo ldconfig /usr/local/lib
- cd -

script:
- go test ./...
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Command M

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# go-hwloc

[![Build Status](https://travis-ci.com/c0mm4nd/go-hwloc.svg?branch=master)](https://travis-ci.com/c0mm4nd/go-hwloc)
[![Go Doc](https://godoc.org/godoc.org/github.com/c0mm4nd/go-hwloc?status.svg)](https://godoc.org/github.com/c0mm4nd/go-hwloc)

## Introduction

Golang binding for static hwloc

## Ready

Install hwloc from your system package manager or compile from the source in https://github.com/open-mpi/hwloc

For example:
```bash
# Static Build
git clone https://github.com/open-mpi/hwloc && cd hwloc
./autogen.sh
./configure --enable-static --disable-shared LDFLAGS="-static"
make LDFLAGS=-all-static
sudo make install
sudo ldconfig /usr/local/lib
```

## Usage

```go
import hwloc "github.com/c0mm4nd/go-hwloc"
```

## Extra

- Q: Why not assemble hwloc into go lib?

A: hwloc is a very powerful and platform-based native library, so comparing to provide a simple version, I prefer to let developers compile it by their own hands or the binary for their platform.

- Q: Why build fails when using bazel?

A: Bazel compiling project within a sandbox, which disallow linker find the "external" library, hwloc, so you should write `BUILD.bazel` and `WORKSPACE` for hwloc before using this go binding lib. Actually, it is what tensorflow does, and you can learn from [their practice](https://github.com/tensorflow/tensorflow/tree/master/third_party/hwloc)

# Hwloc

## Introduction

The Hardware Locality (hwloc) software project aims at easing the process of
discovering hardware resources in parallel architectures. It offers
command-line tools and a C API for consulting these resources, their locality,
attributes, and interconnection. hwloc primarily aims at helping
high-performance computing (HPC) applications, but is also applicable to any
project seeking to exploit code and/or data locality on modern computing
platforms.

hwloc is actually made of two subprojects distributed together:

* The original hwloc project for describing the internals of computing nodes.
It is described in details starting at section Hardware Locality (hwloc)
Introduction.
* The network-oriented companion called netloc (Network Locality), described
in details starting with section Network Locality (netloc).

See also the Related pages tab above for links to other sections.

Netloc may be disabled, but the original hwloc cannot. Both hwloc and netloc
APIs are documented after these sections.
85 changes: 85 additions & 0 deletions bitmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// +build !windows

package hwloc

//#cgo LDFLAGS: -lhwloc
//#cgo LDFLAGS: -static -static-libgcc
// #include <hwloc.h>
// #include <hwloc/bitmap.h>
import "C"
import "unsafe"

// BitMap is a struct containing a slice of bytes,
// being used as a bitmap.
type BitMap struct {
bm C.hwloc_bitmap_t
}

// NewBitmap returns a BitMap. It requires a size. A bitmap with a size of
// eight or less will be one byte in size, and so on.
func NewBitmap(set C.hwloc_bitmap_t) BitMap {
b := BitMap{
bm: set,
}
if set == nil {
b.bm = C.hwloc_bitmap_alloc()
}
return b
}

// Destroy free the BitMap
func (b BitMap) Destroy() {
if b.bm != nil {
C.hwloc_bitmap_free(b.bm)
}
}

// Set sets a position in
// the bitmap to 1.
func (b BitMap) Set(i uint64) error {
C.hwloc_bitmap_set(b.bm, C.uint(i))
return nil
}

// Unset sets a position in
// the bitmap to 0.
func (b BitMap) Unset(i uint64) error {
C.hwloc_bitmap_clr(b.bm, C.uint(i))
return nil
}

// Values returns a slice of ints
// represented by the values in the bitmap.
func (b BitMap) Values() ([]uint64, error) {
list := make([]uint64, 0)
return list, nil
}

// IsSet returns a boolean indicating whether the bit is set for the position in question.
func (b BitMap) IsSet(i uint64) (bool, error) {
if C.hwloc_bitmap_isset(b.bm, C.uint(i)) == 1 {
return true, nil
}
return false, nil
}

// IsZero Test whether bitmap is empty
// return 1 if bitmap is empty, 0 otherwise.
func (b BitMap) IsZero() (bool, error) {
if C.hwloc_bitmap_iszero(b.bm) == 1 {
return true, nil
}
return false, nil
}

func (b BitMap) String() string {
var bitmap = C.CString("")
defer C.free(unsafe.Pointer(bitmap))
C.hwloc_bitmap_asprintf(&bitmap, b.bm)
var res = C.GoString(bitmap)
return res
}

func FromString(input string) (BitMap, error) {
return NewBitmap(nil), nil
}
83 changes: 83 additions & 0 deletions bitmap_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package hwloc

//#cgo LDFLAGS: -lhwloc
//#cgo LDFLAGS: -static -static-libgcc
// #include <hwloc.h>
// #include <hwloc/bitmap.h>
import "C"
import "unsafe"

// BitMap is a struct containing a slice of bytes,
// being used as a bitmap.
type BitMap struct {
bm C.hwloc_bitmap_t
}

// NewBitmap returns a BitMap. It requires a size. A bitmap with a size of
// eight or less will be one byte in size, and so on.
func NewBitmap(set C.hwloc_bitmap_t) BitMap {
b := BitMap{
bm: set,
}
if set == nil {
b.bm = C.hwloc_bitmap_alloc()
}
return b
}

// Destroy free the BitMap
func (b BitMap) Destroy() {
if b.bm != nil {
C.hwloc_bitmap_free(b.bm)
}
}

// Set sets a position in
// the bitmap to 1.
func (b BitMap) Set(i uint64) error {
C.hwloc_bitmap_set(b.bm, C.uint(i))
return nil
}

// Unset sets a position in
// the bitmap to 0.
func (b BitMap) Unset(i uint64) error {
C.hwloc_bitmap_clr(b.bm, C.uint(i))
return nil
}

// Values returns a slice of ints
// represented by the values in the bitmap.
func (b BitMap) Values() ([]uint64, error) {
list := make([]uint64, 0)
return list, nil
}

// IsSet returns a boolean indicating whether the bit is set for the position in question.
func (b BitMap) IsSet(i uint64) (bool, error) {
if C.hwloc_bitmap_isset(b.bm, C.uint(i)) == 1 {
return true, nil
}
return false, nil
}

// IsZero Test whether bitmap is empty
// return 1 if bitmap is empty, 0 otherwise.
func (b BitMap) IsZero() (bool, error) {
if C.hwloc_bitmap_iszero(b.bm) == 1 {
return true, nil
}
return false, nil
}

func (b BitMap) String() string {
var bitmap = C.CString("")
defer C.free(unsafe.Pointer(bitmap))
C.hwloc_bitmap_asprintf(&bitmap, b.bm)
var res = C.GoString(bitmap)
return res
}

func FromString(input string) (BitMap, error) {
return NewBitmap(nil), nil
}
38 changes: 38 additions & 0 deletions cpuset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// +build !windows

package hwloc

//#cgo LDFLAGS: -lhwloc
//#cgo LDFLAGS: -static -static-libgcc
// #include <stdint.h>
// #include <hwloc.h>
import "C"

// HwlocCPUSet A CPU set is a bitmap whose bits are set according to CPU physical OS indexes.
/*
* It may be consulted and modified with the bitmap API as any
* ::hwloc_bitmap_t (see hwloc/bitmap.h).
*
* Each bit may be converted into a PU object using
* hwloc_get_pu_obj_by_os_index().
*/
type HwlocCPUSet struct {
BitMap
}

// NewCPUSet create a HwlocCPUSet instance based on hwloc_cpuset_t
func NewCPUSet(cpuset C.hwloc_cpuset_t) *HwlocCPUSet {
var bm = NewBitmap(cpuset)
return &HwlocCPUSet{
BitMap: bm,
}
}

func (set HwlocCPUSet) hwloc_cpuset_t() C.hwloc_cpuset_t {
return set.BitMap.bm
}

// Destroy free the HwlocCPUSet object
func (set HwlocCPUSet) Destroy() {
set.BitMap.Destroy()
}
Loading

0 comments on commit 0e7d07c

Please sign in to comment.