Skip to content

MetaX-MACA/go-mxsml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-mxsml

Overview

This repository provides Go bindings for the [MetaX System Management Library(MXSML)]

Quick Start

This repository provides two sets of go-mxsml interfaces:

  1. One set (pkg/mxsml) follows the original module structure of the mxsml API.

  2. The other set (pkg/mxsmlextension) adopts the interface style like go-nvml.

The following example demonstrates how to retrieve the number of current devices and the driver version of device.

package main

import (
	"fmt"
	"log"

	"github.com/MetaX-MACA/go-mxsml/pkg/mxsml"
)

func main() {
	ret := mxsml.MxSmlInit()
	if ret != mxsml.MXSML_Success {
		log.Fatal(mxsml.MxSmlGetErrorString(ret))
	}
	defer mxsml.MxSmlShutDown()

	count := mxsml.MxSmlGetDeviceCount()
	fmt.Printf("device count: %d\n", count)

	for i := range count {
		deviceInfo, ret := mxsml.MxSmlGetDeviceInfo(i)
		if ret != mxsml.MXSML_Success {
			fmt.Printf("get device info failed: %s\n", mxsml.MxSmlGetErrorString(ret))
			continue
		}
		deviceId := deviceInfo.DeviceId

		version, ret := mxsml.MxSmlGetDeviceVersion(deviceId, mxsml.MXSML_Version_Driver)
		if ret != mxsml.MXSML_Success {
			fmt.Printf("get driver version failed: %s\n", mxsml.MxSmlGetErrorString(ret))
		} else {
			fmt.Printf("device Id: %d, driver version: %s\n", deviceId, version)
		}
	}
}

The output of this example may be:

$ go run main.go
device count: 4
device Id: 0, driver version: 2.14.0
device Id: 1, driver version: 2.14.0
device Id: 2, driver version: 2.14.0
device Id: 3, driver version: 2.14.0

For more usage examples of both interfaces, please refer to the demo.

Golang Binding Code

This project uses the c-for-go tool to convert the mxsml interface files (written in C) into Go (Golang) format. Moreover, a number of wrappers have been added on this basis to better align with Go's idiomatic style. Typically, the code generated by c-for-go does not need to be updated unless the mxsml header files are modified.

Code Structure

There are two top-level directories in this repository:

  • /demo
  • /gen
  • /pkg

The /demo directory contains examples corresponding to the two sets of interfaces. The /gen directory contains the header files and rule YAML files dependent on the c-for-go tool. The /pkg directory contains the Go files converted by c-for-go and the manually encapsulated wrapper files.

Generate Binding Code

$ make gen

$ make gen-extension

Build demo

$ make demo

Execute demo

./demo/bin/mxsmlDemo

./demo/bin/mxsmlExtDemo

Note: To use the go-mxsml interface, ensure that the mxsml dynamic library exists in one of the following paths.

  • /opt/mxdriver/lib/libmxsml.so
  • /opt/maca/lib/libmxsml.so
  • /opt/mxn100/lib/libmxsml.so

About

Go bindings for the MetaX System Management Library(MXSML)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors