本文整理汇总了C#中cudnnStatus类的典型用法代码示例。如果您正苦于以下问题:C# cudnnStatus类的具体用法?C# cudnnStatus怎么用?C# cudnnStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
cudnnStatus类属于命名空间,在下文中一共展示了cudnnStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CudaDNNContext
/// <summary>
/// </summary>
public CudaDNNContext()
{
_handle = new cudnnHandle();
res = CudaDNNNativeMethods.cudnnCreate(ref _handle);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnCreate", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例2: TensorDescriptor
/// <summary>
/// </summary>
public TensorDescriptor()
{
_desc = new cudnnTensorDescriptor();
res = CudaDNNNativeMethods.cudnnCreateTensorDescriptor(ref _desc);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnCreateTensorDescriptor", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例3: SpatialTransformerDescriptor
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public SpatialTransformerDescriptor(CudaDNNContext context)
{
_handle = context.Handle;
_desc = new cudnnSpatialTransformerDescriptor();
res = CudaDNNNativeMethods.cudnnCreateSpatialTransformerDescriptor(ref _desc);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnCreateSpatialTransformerDescriptor", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例4: SetRNNDescriptor
/// <summary>
/// This function initializes a previously created RNN descriptor object.
/// </summary>
/// <param name="hiddenSize">Size of the internal hidden state for each layer.</param>
/// <param name="seqLength">Number of iterations to unroll over.</param>
/// <param name="numLayers">Number of layers.</param>
/// <param name="dropoutDesc">Handle to a previously created and initialized dropout descriptor.</param>
/// <param name="inputMode">Specifies the behavior at the input to the first layer.</param>
/// <param name="direction">Specifies the recurrence pattern. (eg. bidirectional)</param>
/// <param name="mode">The type of RNN to compute.</param>
/// <param name="dataType">Math precision.</param>
public void SetRNNDescriptor(
int hiddenSize,
int seqLength,
int numLayers,
DropoutDescriptor dropoutDesc, // Between layers, not between recurrent steps.
cudnnRNNInputMode inputMode,
cudnnDirectionMode direction,
cudnnRNNMode mode,
cudnnDataType dataType)
{
res = CudaDNNNativeMethods.cudnnSetRNNDescriptor(_desc, hiddenSize, seqLength, numLayers, dropoutDesc.Desc, inputMode, direction, mode, dataType);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnSetRNNDescriptor", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例5: TransformTensor
/* Tensor layout conversion helper (dest = alpha * src + beta * dest) */
public void TransformTensor(float alpha,
TensorDescriptor srcDesc,
CudaDeviceVariable<float> srcData,
float beta,
TensorDescriptor destDesc,
CudaDeviceVariable<float> destData
)
{
res = CudaDNNNativeMethods.cudnnTransformTensor(_handle, ref alpha, srcDesc.Desc, srcData.DevicePointer, ref beta, destDesc.Desc, destData.DevicePointer);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnTransformTensor", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例6: SetTensorNdDescriptor
/// <summary>
/// This function initializes a previously created generic Tensor descriptor object.
/// </summary>
/// <param name="dataType">Data type.</param>
/// <param name="nbDims">Dimension of the tensor.</param>
/// <param name="dimA">Array of dimension nbDims that contain the size of the tensor for every dimension.</param>
/// <param name="strideA">Array of dimension nbDims that contain the stride of the tensor for every dimension.</param>
public void SetTensorNdDescriptor(cudnnDataType dataType,
int nbDims,
int[] dimA,
int[] strideA
)
{
res = CudaDNNNativeMethods.cudnnSetTensorNdDescriptor(_desc, dataType, nbDims, dimA, strideA);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnSetTensorNdDescriptor", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例7: GetTensor4dDescriptor
/// <summary>
/// This function queries the parameters of the previouly initialized Tensor4D descriptor object.
/// </summary>
/// <param name="dataType">Data type.</param>
/// <param name="n">Number of images.</param>
/// <param name="c">Number of feature maps per image.</param>
/// <param name="h">Height of each feature map.</param>
/// <param name="w">Width of each feature map.</param>
/// <param name="nStride">Stride between two consecutive images.</param>
/// <param name="cStride">Stride between two consecutive feature maps.</param>
/// <param name="hStride">Stride between two consecutive rows.</param>
/// <param name="wStride">Stride between two consecutive columns.</param>
public void GetTensor4dDescriptor(ref cudnnDataType dataType, // image data type
ref int n, // number of inputs (batch size)
ref int c, // number of input feature maps
ref int h, // height of input section
ref int w, // width of input section
ref int nStride,
ref int cStride,
ref int hStride,
ref int wStride
)
{
res = CudaDNNNativeMethods.cudnnGetTensor4dDescriptor(_desc, ref dataType, ref n, ref c, ref h, ref w, ref nStride, ref cStride, ref hStride, ref wStride);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnGetTensor4dDescriptor", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例8: SetPoolingNdDescriptor
public void SetPoolingNdDescriptor(cudnnPoolingMode mode,
int nbDims,
int[] windowDimA,
int[] paddingA,
int[] strideA
)
{
res = CudaDNNNativeMethods.cudnnSetPoolingNdDescriptor(_desc, mode, nbDims, windowDimA, paddingA, strideA);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnSetPoolingNdDescriptor", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例9: RNNForwardTraining
/// <summary>
/// This routine executes the recurrent neural network described by rnnDesc with inputs x, hx, cx, weights w
/// and outputs y, hy, cy. workspace is required for intermediate storage. reserveSpace stores data required
/// for training. The same reserveSpace data must be used for future calls to cudnnRNNBackwardData and
/// cudnnRNNBackwardWeights if these execute on the same input data.
/// </summary>
/// <param name="xDesc">An array of tensor descriptors describing the input to each recurrent iteration. Each
/// tensor descriptor must have the same first dimension. The second dimension of the tensors may decrease
/// from element n to element n+1 but may not increase. The tensor must be fully packed.</param>
/// <param name="x">Data pointer to GPU memory associated with the tensor descriptors in the array xDesc.</param>
/// <param name="hxDesc">Handle to a previously initialized tensor descriptor describing the initial hidden state
/// of the RNN. The first dimension of the tensor must match the hiddenSize argument passed to the
/// cudnnSetRNNDescriptor call used to initialize rnnDesc. The second dimension must match the second
/// dimension of the first tensor described in xDesc. The third dimension must match the numLayers argument
/// passed to the cudnnSetRNNDescriptor call used to initialize rnnDesc. The tensor must be fully packed.</param>
/// <param name="hx">Data pointer to GPU memory associated with the tensor descriptor hxDesc. If a NULL pointer
/// is passed, the initial hidden state of the network will be initialized to zero.</param>
/// <param name="cxDesc">Handle to a previously initialized tensor descriptor describing the initial
/// cell state for LSTM networks. The first dimension of the tensor must match the hiddenSize argument
/// passed to the cudnnSetRNNDescriptor call used to initialize rnnDesc. The second dimension must match
/// the second dimension of the first tensor described in xDesc. The third dimension must match the numLayers
/// argument passed to the cudnnSetRNNDescriptor call used to initialize rnnDesc. The tensor must be fully
/// packed.</param>
/// <param name="cx">Data pointer to GPU memory associated with the tensor descriptor cxDesc. If a NULL pointer is
/// passed, the initial cell state of the network will be initialized to zero.</param>
/// <param name="wDesc">Handle to a previously initialized filter descriptor describing the weights for the RNN.</param>
/// <param name="w">Data pointer to GPU memory associated with the filter descriptor wDesc.</param>
/// <param name="yDesc">An array of tensor descriptors describing the output from each recurrent iteration. The first
/// dimension of the tensor depends on the direction argument passed to the cudnnSetRNNDescriptor
/// call used to initialize rnnDesc:
/// * If direction is CUDNN_UNIDIRECTIONAL the first dimension should match the hiddenSize
/// argument passed to cudnnSetRNNDescriptor.
/// * If direction is CUDNN_BIDIRECTIONAL the first dimension should match double the hiddenSize
/// argument passed to cudnnSetRNNDescriptor.
/// The second dimension of the tensor n must match the second dimension of the tensor
/// n in xDesc. The tensor must be fully packed.</param>
/// <param name="y">Data pointer to GPU memory associated with the output tensor descriptor yDesc.</param>
/// <param name="hyDesc">Handle to a previously initialized tensor descriptor describing the final
/// hidden state of the RNN. The first dimension of the tensor must match the hiddenSize argument passed to the
/// cudnnSetRNNDescriptor call used to initialize rnnDesc. The second dimension must match the second dimension
/// of the first tensor described in xDesc. The third dimension must match the numLayers argument passed to the
/// cudnnSetRNNDescriptor call used to initialize rnnDesc. The tensor must be fully packed.</param>
/// <param name="hy">Data pointer to GPU memory associated with the tensor descriptor hyDesc. If a
/// NULL pointer is passed, the final hidden state of the network will not be saved.</param>
/// <param name="cyDesc">Handle to a previously initialized tensor descriptor describing the final cell state
/// for LSTM networks. The first dimension of the tensor must match the hiddenSize argument passed to the
/// cudnnSetRNNDescriptor call used to initialize rnnDesc. The second dimension must match the second dimension
/// of the first tensor described in xDesc. The third dimension must match the numLayers argument passed to the
/// cudnnSetRNNDescriptor call used to initialize rnnDesc. The tensor must be fully packed.</param>
/// <param name="cy">Data pointer to GPU memory associated with the tensor descriptor cyDesc. If a NULL pointer is
/// passed, the final cell state of the network will be not be saved.</param>
/// <param name="workspace">Data pointer to GPU memory to be used as a workspace for this call.</param>
/// <param name="workSpaceSizeInBytes">Specifies the size in bytes of the provided workspace.</param>
/// <param name="reserveSpace">Data pointer to GPU memory to be used as a reserve space for this call.</param>
/// <param name="reserveSpaceSizeInBytes">Specifies the size in bytes of the provided reserveSpace.</param>
public void RNNForwardTraining(
TensorDescriptor[] xDesc,
CudaDeviceVariable<double> x,
TensorDescriptor hxDesc,
CudaDeviceVariable<double> hx,
TensorDescriptor cxDesc,
CudaDeviceVariable<double> cx,
FilterDescriptor wDesc,
CudaDeviceVariable<double> w,
TensorDescriptor[] yDesc,
CudaDeviceVariable<double> y,
TensorDescriptor hyDesc,
CudaDeviceVariable<double> hy,
TensorDescriptor cyDesc,
CudaDeviceVariable<double> cy,
CudaDeviceVariable<byte> workspace,
SizeT workSpaceSizeInBytes,
CudaDeviceVariable<byte> reserveSpace,
SizeT reserveSpaceSizeInBytes)
{
var a1 = xDesc.Select(q => q.Desc).ToArray();
var a2 = yDesc.Select(q => q.Desc).ToArray();
res = CudaDNNNativeMethods.cudnnRNNForwardTraining(
_handle, _desc, a1, x.DevicePointer, hxDesc.Desc, hx.DevicePointer, cxDesc.Desc, cx.DevicePointer, wDesc.Desc, w.DevicePointer,
a2, y.DevicePointer, hyDesc.Desc, hy.DevicePointer, cyDesc.Desc, cy.DevicePointer, workspace.DevicePointer, workSpaceSizeInBytes, reserveSpace.DevicePointer, reserveSpaceSizeInBytes);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnRNNForwardTraining", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例10: RNNBackwardWeights
/// <summary>
/// This routine accumulates weight gradients dw from the recurrent neural network described
/// by rnnDesc with inputs x, hx, and outputs y. The mode of operation in this case is additive,
/// the weight gradients calculated will be added to those already existing in dw. workspace
/// is required for intermediate storage. The data in reserveSpace must have previously been
/// generated by cudnnRNNBackwardData.
/// </summary>
/// <param name="xDesc">An array of tensor descriptors describing the input to each recurrent iteration.
/// Each tensor descriptor must have the same first dimension. The second dimension of the tensors may
/// decrease from element n to element n+1 but may not increase. The tensor must be fully packed.</param>
/// <param name="x">Data pointer to GPU memory associated with the tensor descriptors in the array xDesc.</param>
/// <param name="hxDesc">Handle to a previously initialized tensor descriptor describing the initial hidden
/// state of the RNN. The first dimension of the tensor must match the hiddenSize argument passed to the
/// cudnnSetRNNDescriptor call used to initialize rnnDesc. The second dimension must match the second dimension
/// of the first tensor described in xDesc. The third dimension must match the numLayers argument passed to
/// the cudnnSetRNNDescriptor call used to initialize rnnDesc. The tensor must be fully packed. </param>
/// <param name="hx">Data pointer to GPU memory associated with the tensor descriptor hxDesc. If
/// a NULL pointer is passed, the initial hidden state of the network will be initialized to zero.</param>
/// <param name="yDesc">An array of tensor descriptors describing the output from each
/// recurrent iteration. The first dimension of the tensor depends on the direction
/// argument passed to the cudnnSetRNNDescriptor call used to initialize rnnDesc:
/// * If direction is CUDNN_UNIDIRECTIONAL the first dimension should match the hiddenSize
/// argument passed to cudnnSetRNNDescriptor.
/// * If direction is CUDNN_BIDIRECTIONAL the first dimension should match double the hiddenSize
/// argument passed to cudnnSetRNNDescriptor.
/// The second dimension of the tensor n must match the second dimension of the tensor n in dyDesc.
/// The tensor must be fully packed.</param>
/// <param name="y">Data pointer to GPU memory associated with the output tensor descriptor yDesc.</param>
/// <param name="workspace">Data pointer to GPU memory to be used as a workspace for this call.</param>
/// <param name="workSpaceSizeInBytes">Specifies the size in bytes of the provided workspace.</param>
/// <param name="dwDesc">Handle to a previously initialized filter descriptor describing the gradients of the weights for the RNN.</param>
/// <param name="dw">Data pointer to GPU memory associated with the filter descriptor dwDesc.</param>
/// <param name="reserveSpace">Data pointer to GPU memory to be used as a reserve space for this call.</param>
/// <param name="reserveSpaceSizeInBytes">Specifies the size in bytes of the provided reserveSpace.</param>
public void RNNBackwardWeights(
TensorDescriptor[] xDesc,
CudaDeviceVariable<float> x,
TensorDescriptor hxDesc,
CudaDeviceVariable<float> hx,
TensorDescriptor[] yDesc,
CudaDeviceVariable<float> y,
CudaDeviceVariable<byte> workspace,
SizeT workSpaceSizeInBytes,
FilterDescriptor dwDesc,
CudaDeviceVariable<float> dw,
CudaDeviceVariable<byte> reserveSpace,
SizeT reserveSpaceSizeInBytes)
{
var a1 = xDesc.Select(q => q.Desc).ToArray();
var a2 = yDesc.Select(q => q.Desc).ToArray();
res = CudaDNNNativeMethods.cudnnRNNBackwardWeights(
_handle, _desc, a1, x.DevicePointer, hxDesc.Desc, hx.DevicePointer, a2, y.DevicePointer, workspace.DevicePointer, workSpaceSizeInBytes, dwDesc.Desc, dw.DevicePointer, reserveSpace.DevicePointer, reserveSpaceSizeInBytes);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnRNNBackwardWeights", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例11: SetLRNDescriptor
// LRN uses a window [center-lookBehind, center+lookAhead], where
// lookBehind = floor( (lrnN-1)/2 ), lookAhead = lrnN-lookBehind-1.
// So for n=10, the window is [k-4...k...k+5] with a total of 10 samples.
// Values of double parameters will be cast down to tensor data type.
public void SetLRNDescriptor(uint lrnN,
double lrnAlpha,
double lrnBeta,
double lrnK
)
{
res = CudaDNNNativeMethods.cudnnSetLRNDescriptor(_desc, lrnN, lrnAlpha, lrnBeta, lrnK);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnSetLRNDescriptor", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例12: cudnnDivisiveNormalizationBackward
public void cudnnDivisiveNormalizationBackward(
cudnnDivNormMode mode,
float alpha,
cudnnTensorDescriptor srcDesc, // same desc for diff, means, temp, temp2
CUdeviceptr srcData,
CUdeviceptr srcMeansData, // if NULL, means are assumed to be zero
CUdeviceptr srcDiffData,
CUdeviceptr tempData,
CUdeviceptr tempData2,
float betaData,
cudnnTensorDescriptor destDataDesc, // same desc for dest, means, meansDiff
CUdeviceptr destDataDiff, // output data differential
CUdeviceptr destMeansDiff // output means differential, can be NULL
)
{
res = CudaDNNNativeMethods.cudnnDivisiveNormalizationBackward(_handle, _desc, mode, ref alpha, srcDesc, srcData, srcMeansData, srcDiffData, tempData, tempData2, ref betaData, destDataDesc, destDataDiff, destMeansDiff);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnDivisiveNormalizationBackward", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例13: cudnnLRNCrossChannelForward
public void cudnnLRNCrossChannelForward(
cudnnLRNMode lrnMode,
double alpha,
cudnnTensorDescriptor srcDesc,
CUdeviceptr srcData,
double beta,
cudnnTensorDescriptor destDesc,
CUdeviceptr destData)
{
res = CudaDNNNativeMethods.cudnnLRNCrossChannelForward(_handle, _desc, lrnMode, ref alpha, srcDesc, srcData, ref beta, destDesc, destData);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnLRNCrossChannelForward", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例14: cudnnDivisiveNormalizationForward
public void cudnnDivisiveNormalizationForward(
cudnnDivNormMode mode,
double alpha,
cudnnTensorDescriptor srcDesc, // same desc for means, temp, temp2
CUdeviceptr srcData,
CUdeviceptr srcMeansData, // if NULL, means are assumed to be zero
CUdeviceptr tempData,
CUdeviceptr tempData2,
double beta,
cudnnTensorDescriptor destDesc,
CUdeviceptr destData)
{
res = CudaDNNNativeMethods.cudnnDivisiveNormalizationForward(_handle, _desc, mode, ref alpha, srcDesc, srcData, srcMeansData, tempData, tempData2, ref beta, destDesc, destData);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnDivisiveNormalizationForward", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}
示例15: ActivationBackward
/* Function to perform backward activation */
public void ActivationBackward(cudnnActivationMode mode,
double alpha,
TensorDescriptor srcDesc,
CudaDeviceVariable<double> srcData,
TensorDescriptor srcDiffDesc,
CudaDeviceVariable<double> srcDiffData,
TensorDescriptor destDesc,
CudaDeviceVariable<double> destData,
double beta,
TensorDescriptor destDiffDesc,
CudaDeviceVariable<double> destDiffData
)
{
res = CudaDNNNativeMethods.cudnnActivationBackward(_handle, mode, ref alpha, srcDesc.Desc, srcData.DevicePointer, srcDiffDesc.Desc, srcDiffData.DevicePointer, destDesc.Desc, destData.DevicePointer, ref beta, destDiffDesc.Desc, destDiffData.DevicePointer);
Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cudnnActivationForward", res));
if (res != cudnnStatus.Success) throw new CudaDNNException(res);
}