miopen

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package miopen provides low-level bindings for the AMD MIOpen library using purego dlopen. No build tags required; use miopen.Available() to check runtime availability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available returns true if MIOpen is loadable on this machine.

Types

type ActivationDescriptor

type ActivationDescriptor struct {
	// contains filtered or unexported fields
}

ActivationDescriptor wraps miopenActivationDescriptor_t.

func CreateActivationDescriptor

func CreateActivationDescriptor() (*ActivationDescriptor, error)

CreateActivationDescriptor creates a new activation descriptor.

func (*ActivationDescriptor) Destroy

func (a *ActivationDescriptor) Destroy() error

Destroy releases the activation descriptor.

func (*ActivationDescriptor) Set

func (a *ActivationDescriptor) Set(mode ActivationMode, alpha, beta, gamma float64) error

Set configures the activation descriptor.

type ActivationMode

type ActivationMode int

ActivationMode mirrors miopenActivationMode_t.

const (
	ActivationReLU    ActivationMode = 3 // miopenActivationRELU
	ActivationSigmoid ActivationMode = 0 // miopenActivationLOGISTIC
	ActivationTanh    ActivationMode = 2 // miopenActivationTANH
	ActivationELU     ActivationMode = 6 // miopenActivationELU
)

type BatchNormMode

type BatchNormMode int

BatchNormMode mirrors miopenBatchNormMode_t.

const (
	BatchNormPerActivation BatchNormMode = 0 // miopenBNPerActivation
	BatchNormSpatial       BatchNormMode = 1 // miopenBNSpatial
)

type ConvMode

type ConvMode int

ConvMode mirrors miopenConvolutionMode_t.

const (
	ConvolutionMode ConvMode = 0 // miopenConvolution
	TransposeMode   ConvMode = 1 // miopenTranspose
)

type ConvolutionDescriptor

type ConvolutionDescriptor struct {
	// contains filtered or unexported fields
}

ConvolutionDescriptor wraps miopenConvolutionDescriptor_t.

func CreateConvolutionDescriptor

func CreateConvolutionDescriptor() (*ConvolutionDescriptor, error)

CreateConvolutionDescriptor creates a new convolution descriptor.

func (*ConvolutionDescriptor) Destroy

func (c *ConvolutionDescriptor) Destroy() error

Destroy releases the convolution descriptor.

func (*ConvolutionDescriptor) Set2d

func (c *ConvolutionDescriptor) Set2d(padH, padW, strH, strW, dilH, dilW int, mode ConvMode) error

Set2d configures a 2D convolution descriptor.

func (*ConvolutionDescriptor) SetGroupCount

func (c *ConvolutionDescriptor) SetGroupCount(groups int) error

SetGroupCount sets the group count for grouped convolutions.

type DataType

type DataType int

DataType mirrors miopenDataType_t.

const (
	Float32 DataType = 1 // miopenFloat
	Float16 DataType = 2 // miopenHalf
)

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

Handle wraps a miopenHandle_t (opaque pointer).

func CreateHandle

func CreateHandle() (*Handle, error)

CreateHandle creates a new MIOpen handle.

func (*Handle) ActivationForward

func (h *Handle) ActivationForward(
	actDesc *ActivationDescriptor,
	alpha float32,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	beta float32,
	yDesc *TensorDescriptor, y unsafe.Pointer,
) error

ActivationForward applies an activation function.

func (*Handle) BatchNormalizationForwardInference

func (h *Handle) BatchNormalizationForwardInference(
	mode BatchNormMode,
	alpha, beta float32,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	yDesc *TensorDescriptor, y unsafe.Pointer,
	bnScaleBiasMeanVarDesc *TensorDescriptor,
	scale, bias, mean, variance unsafe.Pointer,
	epsilon float64,
) error

BatchNormalizationForwardInference performs batch normalization in inference mode.

func (*Handle) ConvolutionForward

func (h *Handle) ConvolutionForward(
	alpha float32,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	wDesc *TensorDescriptor, w unsafe.Pointer,
	convDesc *ConvolutionDescriptor,
	algo uintptr,
	workspace unsafe.Pointer, wsSize int,
	beta float32,
	yDesc *TensorDescriptor, y unsafe.Pointer,
) error

ConvolutionForward performs the forward convolution.

func (*Handle) ConvolutionForwardGetWorkspaceSize

func (h *Handle) ConvolutionForwardGetWorkspaceSize(
	xDesc *TensorDescriptor,
	wDesc *TensorDescriptor,
	convDesc *ConvolutionDescriptor,
	yDesc *TensorDescriptor,
) (int, error)

ConvolutionForwardGetWorkspaceSize returns the workspace size in bytes.

func (*Handle) Destroy

func (h *Handle) Destroy() error

Destroy releases the MIOpen handle.

func (*Handle) FindConvolutionForwardAlgorithm

func (h *Handle) FindConvolutionForwardAlgorithm(
	xDesc *TensorDescriptor, x unsafe.Pointer,
	wDesc *TensorDescriptor, w unsafe.Pointer,
	convDesc *ConvolutionDescriptor,
	yDesc *TensorDescriptor, y unsafe.Pointer,
	workspace unsafe.Pointer, wsSize int,
) (uintptr, error)

FindConvolutionForwardAlgorithm finds the best convolution algorithm. Returns the algorithm enum value suitable for ConvolutionForward.

func (*Handle) GetPoolingForwardOutputDim

func (h *Handle) GetPoolingForwardOutputDim(
	poolDesc *PoolingDescriptor,
	xDesc *TensorDescriptor,
) (n, c, outH, outW int, err error)

GetPoolingForwardOutputDim returns the output dimensions for a pooling operation.

func (*Handle) OpTensorAdd

func (h *Handle) OpTensorAdd(
	alpha float32,
	bDesc *TensorDescriptor, b unsafe.Pointer,
	beta float32,
	yDesc *TensorDescriptor, y unsafe.Pointer,
) error

OpTensorAdd adds tensors: y = alpha * b + beta * y.

func (*Handle) PoolingForward

func (h *Handle) PoolingForward(
	poolDesc *PoolingDescriptor,
	alpha float32,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	beta float32,
	yDesc *TensorDescriptor, y unsafe.Pointer,
	workspaceIndex bool,
	workspace unsafe.Pointer, wsSize int,
) error

PoolingForward performs 2D pooling.

func (*Handle) PoolingGetWorkSpaceSize

func (h *Handle) PoolingGetWorkSpaceSize(yDesc *TensorDescriptor) (int, error)

PoolingGetWorkSpaceSize returns the workspace size for pooling.

func (*Handle) SetStream

func (h *Handle) SetStream(streamPtr unsafe.Pointer) error

SetStream associates a HIP stream with this MIOpen handle.

func (*Handle) SoftmaxForward

func (h *Handle) SoftmaxForward(
	algo SoftmaxAlgorithm, mode SoftmaxMode,
	alpha float32,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	beta float32,
	yDesc *TensorDescriptor, y unsafe.Pointer,
) error

SoftmaxForward computes softmax.

type MIOpenLib

type MIOpenLib struct {
	// contains filtered or unexported fields
}

MIOpenLib holds dlopen handles and resolved function pointers for MIOpen functions. All function pointers are resolved at Open() time via dlsym.

func Lib

func Lib() *MIOpenLib

Lib returns the global MIOpenLib instance, or nil if not available.

func Open

func Open() (*MIOpenLib, error)

Open loads libMIOpen via dlopen and resolves all function pointers.

type PoolingDescriptor

type PoolingDescriptor struct {
	// contains filtered or unexported fields
}

PoolingDescriptor wraps miopenPoolingDescriptor_t.

func CreatePoolingDescriptor

func CreatePoolingDescriptor() (*PoolingDescriptor, error)

CreatePoolingDescriptor creates a new pooling descriptor.

func (*PoolingDescriptor) Destroy

func (p *PoolingDescriptor) Destroy() error

Destroy releases the pooling descriptor.

func (*PoolingDescriptor) Set2d

func (p *PoolingDescriptor) Set2d(mode PoolingMode, windowH, windowW, padH, padW, strideH, strideW int) error

Set2d configures a 2D pooling descriptor.

type PoolingMode

type PoolingMode int

PoolingMode mirrors miopenPoolingMode_t.

const (
	PoolingMax                    PoolingMode = 0 // miopenPoolingMax
	PoolingAverageCountIncludePad PoolingMode = 1 // miopenPoolingAverageInclusive
	PoolingAverageCountExcludePad PoolingMode = 2 // miopenPoolingAverage
)

type SoftmaxAlgorithm

type SoftmaxAlgorithm int

SoftmaxAlgorithm selects the softmax computation variant.

const (
	SoftmaxAccurate SoftmaxAlgorithm = 0 // MIOPEN_SOFTMAX_ACCURATE
	SoftmaxLog      SoftmaxAlgorithm = 1 // MIOPEN_SOFTMAX_LOG
	SoftmaxFast     SoftmaxAlgorithm = 2 // MIOPEN_SOFTMAX_FAST
)

type SoftmaxMode

type SoftmaxMode int

SoftmaxMode selects the dimension for softmax.

const (
	SoftmaxModeChannel  SoftmaxMode = 1 // MIOPEN_SOFTMAX_MODE_CHANNEL
	SoftmaxModeInstance SoftmaxMode = 0 // MIOPEN_SOFTMAX_MODE_INSTANCE
)

type TensorDescriptor

type TensorDescriptor struct {
	// contains filtered or unexported fields
}

TensorDescriptor wraps miopenTensorDescriptor_t (opaque pointer).

func CreateTensorDescriptor

func CreateTensorDescriptor() (*TensorDescriptor, error)

CreateTensorDescriptor creates a new tensor descriptor.

func (*TensorDescriptor) Destroy

func (t *TensorDescriptor) Destroy() error

Destroy releases the tensor descriptor.

func (*TensorDescriptor) Set4d

func (t *TensorDescriptor) Set4d(dt DataType, n, c, h, w int) error

Set4d configures a 4D NCHW tensor descriptor.

type TensorLayout

type TensorLayout int

TensorLayout selects NCHW or NHWC.

const (
	NCHW TensorLayout = 0
	NHWC TensorLayout = 1
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL