NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
CoreHelpers.h File Reference

Common helper classes and template function implementations. More...

#include <atomic>
#include <functional>
#include <string>
#include <typeinfo>
#include <type_traits>
#include <utility>
#include <nvneural/CoreTypes.h>
#include <nvneural/LayerTypes.h>
#include <nvneural/RefPtr.h>
#include <nvneural/RefObject.h>

Go to the source code of this file.

Classes

struct  std::hash< nvneural::NetworkBackendId >
 Specialization of std::hash for strongly typed network backends. More...
 

Enumerations

enum class  nvneural::TensorDimensionParseOrder : std::uint32_t { Tensor = 0 , Image = 1 }
 Order to read TensorDimension components in for TensorDimensionFromString. More...
 

Functions

TensorDimension nvneural::align (const TensorDimension &dim, const TensorDimension &stepping) noexcept
 Rounds a TensorDimension object up to be a multiple of a provided set of strides. More...
 
constexpr std::size_t nvneural::dataSize (TensorDataType dataType) noexcept
 Returns the size of an individual tensor element of a particular type, similar to sizeof. More...
 
ILoggernvneural::DefaultLogger ()
 Returns a pointer to the default logger for this module. More...
 
template<typename TDividend , typename TDivisor >
constexpr auto nvneural::DivideRoundingUp (TDividend dividend, TDivisor divisor) noexcept
 Division operation, rounding up. More...
 
NeuralResult nvneural::getInputLayerIndex (ILayer *pLayer, ILayer *pInputLayer, size_t *pIndex)
 Retrieves the layer index in the input list. More...
 
void nvneural::SetDefaultLogger (ILogger *pDefaultLogger)
 Sets a default logger for the module.
 
std::vector< std::string > nvneural::split (std::string strToSplit, char delimiter, bool skip_empty=false)
 Splits a string by a delimiter, returns a vector of the split strings. More...
 
std::vector< std::string > nvneural::splitEscape (std::string strToSplit, char delimiter, bool skip_empty=false)
 Splits a string by a delimiter, returns a vector of the split strings. More...
 
NeuralResult nvneural::TensorDimensionFromString (TensorDimension &outDim, const std::string &dimStr, TensorDimensionParseOrder parseOrder, size_t fillValue) noexcept
 Parses a TensorDimension from a UTF-8 string. More...
 
std::string nvneural::TensorDimensionToString (const TensorDimension &dim) noexcept
 Converts a TensorDimension to a UTF-8 string. More...
 

Detailed Description

Common helper classes and template function implementations.

Enumeration Type Documentation

◆ TensorDimensionParseOrder

enum nvneural::TensorDimensionParseOrder : std::uint32_t
strong

Order to read TensorDimension components in for TensorDimensionFromString.

Enumerator
Tensor 

This order is used for parameters that typically describe tensor dimensions.

Channels are parsed in this order:

  • 1 value: C
  • 2 values: H W
  • 3 values: C H W
  • 4 values: N C H W
Image 

This order is used for parameters that typically describe image or kernel sizes.

Channels are parsed in this order:

  • 1 value: H + W (both components receive the same value)
  • 2 values: W H
  • 3 values: W H C
  • 4 values: W H C N

Function Documentation

◆ align()

TensorDimension nvneural::align ( const TensorDimension dim,
const TensorDimension stepping 
)
inlinenoexcept

Rounds a TensorDimension object up to be a multiple of a provided set of strides.

Dimensions are rounded individually by component.

Parameters
dimSize to round up
steppingComponent multiples to round up to

◆ dataSize()

constexpr std::size_t nvneural::dataSize ( TensorDataType  dataType)
inlineconstexprnoexcept

Returns the size of an individual tensor element of a particular type, similar to sizeof.

You should implement your own version of the function if working with custom types; unsupported types will return zero.

Parameters
dataTypeType to query

◆ DefaultLogger()

ILogger * nvneural::DefaultLogger ( )

Returns a pointer to the default logger for this module.

If no logger has been assigned via IPlugin::setDefaultLogger or SetDefaultLogger, the logger will silently ignore all messages sent to it.

◆ DivideRoundingUp()

template<typename TDividend , typename TDivisor >
constexpr auto nvneural::DivideRoundingUp ( TDividend  dividend,
TDivisor  divisor 
)
inlineconstexprnoexcept

Division operation, rounding up.

The primary application of this helper is CUDA grid launches: assuming a grid of "dividend" threads to launch, and a block size of "divisor" threads per block, the return value of this function will be the appropriate number of blocks to launch.

Template Parameters
TDividendType of the dividend; should be integer-like
TDivisorType of the divisor; should be integer-like
Parameters
dividendValue to divide
divisorValue to divide by

◆ getInputLayerIndex()

NeuralResult nvneural::getInputLayerIndex ( ILayer pLayer,
ILayer pInputLayer,
size_t *  pIndex 
)
inline

Retrieves the layer index in the input list.

Parameters
pLayerthe layer to scan inputs from
pInputLayerone of the input layer
pIndexindex output
Returns
Success if pInputLayer is part of the input list, else Failure (in that case *pIndex was untouched)

◆ split()

std::vector<std::string> nvneural::split ( std::string  strToSplit,
char  delimiter,
bool  skip_empty = false 
)
inline

Splits a string by a delimiter, returns a vector of the split strings.

This is generally used when splitting dimensions (IE 1x1 or 1x1,1x1). There is an optional flag that allows skipping of empty split strings.

Parameters
strToSplitthe string to split
delimitersingle character that denotes the delimiter
skip_emptyoptional, skips returning empty split strings
Returns
a vector of the split strings

◆ splitEscape()

std::vector<std::string> nvneural::splitEscape ( std::string  strToSplit,
char  delimiter,
bool  skip_empty = false 
)
inline

Splits a string by a delimiter, returns a vector of the split strings.

This version considers escaped characters.

This is generally used when splitting text strings where escaped characters can be used in the text itself. There is an optional flag that allows skipping of empty split strings.

Parameters
strToSplitthe string to split
delimitersingle character that denotes the delimiter
skip_emptyoptional, skips returning empty split strings
Returns
a vector of the split strings

◆ TensorDimensionFromString()

NeuralResult nvneural::TensorDimensionFromString ( TensorDimension outDim,
const std::string &  dimStr,
TensorDimensionParseOrder  parseOrder,
size_t  fillValue 
)
noexcept

Parses a TensorDimension from a UTF-8 string.

The interpretations of strings like "2x3x4" are determined by the parse order. Alternately, dimensions may be specified explicitly ("2w4c"). Mixed use of implicit and explicit dimensions ("4n5x6") is not permitted within the same input string.

Parameters
outDimTensorDimension variable receiving the parsed value.
dimStrString to parse.
parseOrderOrder for parsing components if not explicit in the string.
fillValueValue to fill unparsed components with.

◆ TensorDimensionToString()

std::string nvneural::TensorDimensionToString ( const TensorDimension dim)
noexcept

Converts a TensorDimension to a UTF-8 string.

The string uses explicit component syntax for unambiguous round-trips through the TensorDimensionFromString function.

Parameters
dimDimension to convert