目录

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.
  1. 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
关于

Go bindings for the MetaX System Management Library(MXSML)

103.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号