cudnn

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: 4 Imported by: 0

Documentation

Overview

Package cudnn provides purego bindings for the NVIDIA cuDNN library. Use Available() to check at runtime whether libcudnn can be loaded.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available returns true if libcudnn can be loaded on this machine.

Types

type ActivationDescriptor

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

ActivationDescriptor wraps a cudnnActivationDescriptor_t.

func CreateActivationDescriptor

func CreateActivationDescriptor() (*ActivationDescriptor, error)

CreateActivationDescriptor allocates 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, nanProp NanPropagation, coef float64) error

Set configures the activation descriptor.

type ActivationMode

type ActivationMode int

ActivationMode maps to cudnnActivationMode_t.

const (
	ActivationSigmoid     ActivationMode = cudnnActivationSigmoid
	ActivationReLU        ActivationMode = cudnnActivationRelu
	ActivationTanh        ActivationMode = cudnnActivationTanh
	ActivationClippedReLU ActivationMode = cudnnActivationClippedRelu
	ActivationELU         ActivationMode = cudnnActivationElu
)

type BatchNormMode

type BatchNormMode int

BatchNormMode maps to cudnnBatchNormMode_t.

const (
	BatchNormPerActivation BatchNormMode = cudnnBatchNormPerActivation
	BatchNormSpatial       BatchNormMode = cudnnBatchNormSpatial
)

type ConvBwdDataAlgo

type ConvBwdDataAlgo int

ConvBwdDataAlgo maps to cudnnConvolutionBwdDataAlgo_t.

const (
	ConvBwdDataAlgo0        ConvBwdDataAlgo = cudnnConvBwdDataAlgo0
	ConvBwdDataAlgo1        ConvBwdDataAlgo = cudnnConvBwdDataAlgo1
	ConvBwdDataAlgoFFT      ConvBwdDataAlgo = cudnnConvBwdDataAlgoFFT
	ConvBwdDataAlgoWinograd ConvBwdDataAlgo = cudnnConvBwdDataAlgoWinograd
)

type ConvBwdFilterAlgo

type ConvBwdFilterAlgo int

ConvBwdFilterAlgo maps to cudnnConvolutionBwdFilterAlgo_t.

const (
	ConvBwdFilterAlgo0        ConvBwdFilterAlgo = cudnnConvBwdFilterAlgo0
	ConvBwdFilterAlgo1        ConvBwdFilterAlgo = cudnnConvBwdFilterAlgo1
	ConvBwdFilterAlgoFFT      ConvBwdFilterAlgo = cudnnConvBwdFilterAlgoFFT
	ConvBwdFilterAlgo3        ConvBwdFilterAlgo = cudnnConvBwdFilterAlgo3
	ConvBwdFilterAlgoWinograd ConvBwdFilterAlgo = cudnnConvBwdFilterAlgoWinograd
)

type ConvFwdAlgo

type ConvFwdAlgo int

ConvFwdAlgo maps to cudnnConvolutionFwdAlgo_t.

const (
	ConvFwdAlgoImplicitGemm        ConvFwdAlgo = cudnnConvFwdAlgoImplicitGemm
	ConvFwdAlgoImplicitPrecompGemm ConvFwdAlgo = cudnnConvFwdAlgoImplicitPrecompGemm
	ConvFwdAlgoGemm                ConvFwdAlgo = cudnnConvFwdAlgoGemm
	ConvFwdAlgoFFT                 ConvFwdAlgo = cudnnConvFwdAlgoFFT
	ConvFwdAlgoWinograd            ConvFwdAlgo = cudnnConvFwdAlgoWinograd
)

type ConvolutionDescriptor

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

ConvolutionDescriptor wraps a cudnnConvolutionDescriptor_t.

func CreateConvolutionDescriptor

func CreateConvolutionDescriptor() (*ConvolutionDescriptor, error)

CreateConvolutionDescriptor allocates 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, strideH, strideW, dilationH, dilationW int, mode ConvolutionMode, dtype DataType) error

Set2d configures the convolution descriptor for 2D convolution.

func (*ConvolutionDescriptor) SetGroupCount

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

SetGroupCount sets the number of groups for grouped convolution.

type ConvolutionMode

type ConvolutionMode int

ConvolutionMode maps to cudnnConvolutionMode_t.

const (
	Convolution      ConvolutionMode = cudnnConvolution
	CrossCorrelation ConvolutionMode = cudnnCrossCorrelation
)

type DataType

type DataType int

DataType maps to cudnnDataType_t.

const (
	Float32 DataType = cudnnDataFloat
	Float64 DataType = cudnnDataDouble
	Float16 DataType = cudnnDataHalf
	Int32   DataType = cudnnDataInt32
	Int8    DataType = cudnnDataInt8
)

type FilterDescriptor

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

FilterDescriptor wraps a cudnnFilterDescriptor_t.

func CreateFilterDescriptor

func CreateFilterDescriptor() (*FilterDescriptor, error)

CreateFilterDescriptor allocates a new filter descriptor.

func (*FilterDescriptor) Destroy

func (f *FilterDescriptor) Destroy() error

Destroy releases the filter descriptor.

func (*FilterDescriptor) Set4d

func (f *FilterDescriptor) Set4d(dtype DataType, format TensorFormat, k, c, h, w int) error

Set4d sets the filter descriptor to a 4D layout (K, C, H, W).

type Handle

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

Handle wraps a cudnnHandle_t. Create one per GPUEngine.

func CreateHandle

func CreateHandle() (*Handle, error)

CreateHandle creates a new cuDNN handle.

func (*Handle) ActivationBackward

func (h *Handle) ActivationBackward(
	actDesc *ActivationDescriptor,
	alpha float32,
	yDesc *TensorDescriptor, y unsafe.Pointer,
	dyDesc *TensorDescriptor, dy unsafe.Pointer,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	beta float32,
	dxDesc *TensorDescriptor, dx unsafe.Pointer,
) error

ActivationBackward computes the gradient of an activation function.

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 element-wise.

func (*Handle) AddTensor

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

AddTensor adds a bias tensor to the output: y = alpha*b + beta*y.

func (*Handle) BatchNormalizationBackward

func (h *Handle) BatchNormalizationBackward(
	mode BatchNormMode,
	alphaDataDiff, betaDataDiff float32,
	alphaParamDiff, betaParamDiff float32,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	dyDesc *TensorDescriptor, dy unsafe.Pointer,
	dxDesc *TensorDescriptor, dx unsafe.Pointer,
	bnScaleBiasDiffDesc *TensorDescriptor,
	bnScale unsafe.Pointer,
	dBnScale, dBnBias unsafe.Pointer,
	epsilon float64,
	saveMean, saveInvVariance unsafe.Pointer,
) error

BatchNormalizationBackward computes gradients for batch normalization.

func (*Handle) BatchNormalizationForwardInference

func (h *Handle) BatchNormalizationForwardInference(
	mode BatchNormMode,
	alpha, beta float32,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	yDesc *TensorDescriptor, y unsafe.Pointer,
	bnScaleBiasMeanVarDesc *TensorDescriptor,
	bnScale, bnBias unsafe.Pointer,
	estimatedMean, estimatedVariance unsafe.Pointer,
	epsilon float64,
) error

BatchNormalizationForwardInference performs batch normalization in inference mode.

func (*Handle) BatchNormalizationForwardTraining

func (h *Handle) BatchNormalizationForwardTraining(
	mode BatchNormMode,
	alpha, beta float32,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	yDesc *TensorDescriptor, y unsafe.Pointer,
	bnScaleBiasMeanVarDesc *TensorDescriptor,
	bnScale, bnBias unsafe.Pointer,
	expAvgFactor float64,
	runningMean, runningVariance unsafe.Pointer,
	epsilon float64,
	saveMean, saveInvVariance unsafe.Pointer,
) error

BatchNormalizationForwardTraining performs batch normalization in training mode.

func (*Handle) ConvolutionBackwardData

func (h *Handle) ConvolutionBackwardData(
	alpha float32,
	wDesc *FilterDescriptor, w unsafe.Pointer,
	dyDesc *TensorDescriptor, dy unsafe.Pointer,
	convDesc *ConvolutionDescriptor,
	algo ConvBwdDataAlgo,
	workspace unsafe.Pointer, workspaceSize int,
	beta float32,
	dxDesc *TensorDescriptor, dx unsafe.Pointer,
) error

ConvolutionBackwardData computes the gradient of the input for 2D convolution.

func (*Handle) ConvolutionBackwardFilter

func (h *Handle) ConvolutionBackwardFilter(
	alpha float32,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	dyDesc *TensorDescriptor, dy unsafe.Pointer,
	convDesc *ConvolutionDescriptor,
	algo ConvBwdFilterAlgo,
	workspace unsafe.Pointer, workspaceSize int,
	beta float32,
	dwDesc *FilterDescriptor, dw unsafe.Pointer,
) error

ConvolutionBackwardFilter computes the gradient of the filter for 2D convolution.

func (*Handle) ConvolutionForward

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

ConvolutionForward performs a forward convolution.

func (*Handle) Destroy

func (h *Handle) Destroy() error

Destroy releases the cuDNN handle resources.

func (*Handle) GetConvolutionBackwardDataWorkspaceSize

func (h *Handle) GetConvolutionBackwardDataWorkspaceSize(
	wDesc *FilterDescriptor,
	dyDesc *TensorDescriptor,
	convDesc *ConvolutionDescriptor,
	dxDesc *TensorDescriptor,
	algo ConvBwdDataAlgo,
) (int, error)

GetConvolutionBackwardDataWorkspaceSize returns the workspace size in bytes.

func (*Handle) GetConvolutionBackwardFilterWorkspaceSize

func (h *Handle) GetConvolutionBackwardFilterWorkspaceSize(
	xDesc *TensorDescriptor,
	dyDesc *TensorDescriptor,
	convDesc *ConvolutionDescriptor,
	dwDesc *FilterDescriptor,
	algo ConvBwdFilterAlgo,
) (int, error)

GetConvolutionBackwardFilterWorkspaceSize returns the workspace size in bytes.

func (*Handle) GetConvolutionForwardWorkspaceSize

func (h *Handle) GetConvolutionForwardWorkspaceSize(
	xDesc *TensorDescriptor,
	wDesc *FilterDescriptor,
	convDesc *ConvolutionDescriptor,
	yDesc *TensorDescriptor,
	algo ConvFwdAlgo,
) (int, error)

GetConvolutionForwardWorkspaceSize returns the workspace size in bytes.

func (*Handle) PoolingBackward

func (h *Handle) PoolingBackward(
	poolDesc *PoolingDescriptor,
	alpha float32,
	yDesc *TensorDescriptor, y unsafe.Pointer,
	dyDesc *TensorDescriptor, dy unsafe.Pointer,
	xDesc *TensorDescriptor, x unsafe.Pointer,
	beta float32,
	dxDesc *TensorDescriptor, dx unsafe.Pointer,
) error

PoolingBackward computes the gradient of a pooling operation.

func (*Handle) PoolingForward

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

PoolingForward performs a forward pooling operation.

func (*Handle) SetStream

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

SetStream associates the handle with a CUDA stream.

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 over the channel dimension.

type NanPropagation

type NanPropagation int

NanPropagation maps to cudnnNanPropagation_t.

const (
	NotPropagateNan NanPropagation = cudnnNotPropagateNan
	PropagateNan    NanPropagation = cudnnPropagateNan
)

type PoolingDescriptor

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

PoolingDescriptor wraps a cudnnPoolingDescriptor_t.

func CreatePoolingDescriptor

func CreatePoolingDescriptor() (*PoolingDescriptor, error)

CreatePoolingDescriptor allocates 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, nanProp NanPropagation, windowH, windowW, padH, padW, strideH, strideW int) error

Set2d configures the pooling descriptor for 2D pooling.

type PoolingMode

type PoolingMode int

PoolingMode maps to cudnnPoolingMode_t.

const (
	PoolingMax                    PoolingMode = cudnnPoolingMax
	PoolingAverageCountIncludePad PoolingMode = cudnnPoolingAverageCountIncludePad
	PoolingAverageCountExcludePad PoolingMode = cudnnPoolingAverageCountExcludePad
)

type SoftmaxAlgorithm

type SoftmaxAlgorithm int

SoftmaxAlgorithm maps to cudnnSoftmaxAlgorithm_t.

const (
	SoftmaxFast     SoftmaxAlgorithm = cudnnSoftmaxFast
	SoftmaxAccurate SoftmaxAlgorithm = cudnnSoftmaxAccurate
	SoftmaxLog      SoftmaxAlgorithm = cudnnSoftmaxLog
)

type SoftmaxMode

type SoftmaxMode int

SoftmaxMode maps to cudnnSoftmaxMode_t.

const (
	SoftmaxModeInstance SoftmaxMode = cudnnSoftmaxModeInstance
	SoftmaxModeChannel  SoftmaxMode = cudnnSoftmaxModeChannel
)

type TensorDescriptor

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

TensorDescriptor wraps a cudnnTensorDescriptor_t.

func CreateTensorDescriptor

func CreateTensorDescriptor() (*TensorDescriptor, error)

CreateTensorDescriptor allocates a new tensor descriptor.

func (*TensorDescriptor) Destroy

func (t *TensorDescriptor) Destroy() error

Destroy releases the tensor descriptor.

func (*TensorDescriptor) Set4d

func (t *TensorDescriptor) Set4d(format TensorFormat, dtype DataType, n, c, h, w int) error

Set4d sets the tensor descriptor to a 4D layout (N, C, H, W).

func (*TensorDescriptor) SetNd

func (t *TensorDescriptor) SetNd(dtype DataType, dims, strides []int) error

SetNd sets the tensor descriptor to an N-dimensional layout.

type TensorFormat

type TensorFormat int

TensorFormat maps to cudnnTensorFormat_t.

const (
	NCHW TensorFormat = cudnnTensorNCHW
	NHWC TensorFormat = cudnnTensorNHWC
)

Jump to

Keyboard shortcuts

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