Rename package to make it clear that this is Go

- I hate the convention of putting "go" on every library wrapper, but
   unfortunately the utility is undeniable.  I don't want people to find
   this repo when they are actually looking for the "real" onnxruntime
   repo.
This commit is contained in:
yalue
2023-02-08 09:47:18 -05:00
parent 0c57c937e4
commit 36dc614e49
6 changed files with 21 additions and 15 deletions

View File

@@ -45,30 +45,30 @@ non-nil in the case of failure.
```go
import (
"fmt"
"github.com/yalue/onnxruntime"
ort "github.com/yalue/onnxruntime_go"
"os"
)
func main() {
// This line may be optional, by default the library will try to load
// "onnxruntime.dll" on Windows, and "onnxruntime.so" on any other system.
onnxruntime.SetSharedLibraryPath("path/to/onnxruntime.so")
ort.SetSharedLibraryPath("path/to/onnxruntime.so")
err := onnxruntime.InitializeEnvironment()
defer onnxruntime.DestroyEnvironment()
err := ort.InitializeEnvironment()
defer ort.DestroyEnvironment()
// To make it easier to work with the C API, this library requires the user
// to create all input and output tensors prior to creating the session.
inputData := []float32{0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}
inputShape := onnxruntime.Shape([]int64{2, 5})
inputTensor, err := onnxruntime.NewTensor(inputShape, inputData)
inputShape := ort.Shape([]int64{2, 5})
inputTensor, err := ort.NewTensor(inputShape, inputData)
defer inputTensor.Destroy()
// This hypothetical network maps a 2x5 input -> 2x3x4 output.
outputShape := onnxruntime.Shape([]int64{2, 3, 4})
outputTensor, err := onnxruntime.NewEmptyTensor[float32](outputShape)
outputShape := ort.Shape([]int64{2, 3, 4})
outputTensor, err := ort.NewEmptyTensor[float32](outputShape)
defer outputTensor.Destroy()
session, err := onnxruntime.NewSession[float32]("path/to/network.onnx",
session, err := ort.NewSession[float32]("path/to/network.onnx",
[]string{"Input 1 Name"}, []string{"Output 1 Name"},
[]*Tensor[float32]{inputTensor}, []*Tensor[float32]{outputTensor})
defer session.Destroy()
@@ -85,5 +85,5 @@ func main() {
}
```
The full documentation can be found at [pkg.go.dev](https://pkg.go.dev/github.com/yalue/onnxruntime).
The full documentation can be found at [pkg.go.dev](https://pkg.go.dev/github.com/yalue/onnxruntime_go).

View File

@@ -2,7 +2,7 @@
// https://github.com/microsoft/onnxruntime. It seeks to provide as simple an
// interface as possible to load and run ONNX-format neural networks from
// Go code.
package onnxruntime
package onnxruntime_go
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package onnxruntime
package onnxruntime_go
import (
"encoding/json"

View File

@@ -1,6 +1,6 @@
//go:build !windows
package onnxruntime
package onnxruntime_go
import (
"fmt"
@@ -41,6 +41,9 @@ func platformCleanup() error {
}
func platformInitializeEnvironment() error {
if onnxSharedLibraryPath == "" {
onnxSharedLibraryPath = "onnxruntime.so"
}
cName := C.CString(onnxSharedLibraryPath)
defer C.free(unsafe.Pointer(cName))
handle := C.dlopen(cName, C.RTLD_LAZY)

View File

@@ -1,6 +1,6 @@
//go:build windows
package onnxruntime
package onnxruntime_go
// This file includes the Windows-specific code for loading the onnxruntime
// library and setting up the environment.
@@ -25,6 +25,9 @@ func platformCleanup() error {
}
func platformInitializeEnvironment() error {
if onnxSharedLibraryPath == "" {
onnxSharedLibraryPath = "onnxruntime.dll"
}
handle, e := syscall.LoadLibrary(onnxSharedLibraryPath)
if e != nil {
return fmt.Errorf("Error loading ONNX shared library \"%s\": %w",

View File

@@ -1,4 +1,4 @@
package onnxruntime
package onnxruntime_go
// This file contains definitions for the generic tensor data types we support.