26 #ifndef NVNEURAL_CORETYPES_H
27 #define NVNEURAL_CORETYPES_H
32 #include <type_traits>
34 #include <initializer_list>
40 class INetworkBackend;
41 class INetworkRuntime;
108 ||
layout != other.layout;
114 return !(*
this != other);
122 return std::tie(
elementType,
layout) < std::tie(other.elementType, other.layout);
127 static_assert(
sizeof(TensorFormat) ==
sizeof(std::uint32_t),
"TensorFormat structure packing not as expected");
177 return (
n == other.
n) && (
c == other.
c) && (
h == other.
h) && (
w == other.
w);
183 return !(*
this == other);
195 static_assert(std::is_standard_layout<TensorDimension>::value,
"TensorDimension must be standard layout");
216 *
this =
Float16(
static_cast<float>(value));
228 operator float()
const;
284 return result <= NeuralResult::Success;
289 return result >= NeuralResult::Failure;
399 template<typename TInterface>
508 virtual
bool memManagedExternally() const noexcept = 0;
515 virtual const
void* data() const noexcept = 0;
621 class MemoryHandle__type;
667 SkipConcatenation = 0xdd13d58fbabb2f5bul,
675 FuseBatchNormAndConvolution = 0xeaffe6d9a4acfdc9ul,
733 void* pDeviceDestination,
736 const
void* pDeviceSource,
744 virtual
NeuralResult setDeviceMemory(
void* pDeviceDestination, std::uint8_t value, std::
size_t byteCount) noexcept = 0;
747 virtual
NeuralResult copyMemoryD2D(
void* pDeviceDestination, const
void* pDeviceSource, std::
size_t byteCount) noexcept = 0;
750 virtual
NeuralResult copyMemoryH2D(
void* pDeviceDestination, const
void* pHostSource, std::
size_t byteCount) noexcept = 0;
753 virtual
NeuralResult copyMemoryD2H(
void* pHostDestination, const
void* pDeviceSource, std::
size_t byteCount) noexcept = 0;
817 virtual
void* getAddressForMemoryBlock(
MemoryHandle handle) noexcept = 0;
826 virtual
size_t getSizeForMemoryBlock(
MemoryHandle handle) noexcept = 0;
869 const
void** ppUploadedWeightsOut,
872 const
void* pWeightsData,
873 std::
size_t weightsDataSize,
876 bool memManagedExternally) noexcept = 0;
888 virtual const
void* getAddressForWeightsData(const
ILayer* pLayer, const
char* pName,
TensorFormat format) const noexcept = 0;
939 virtual
ILayer* getLayerByIndex(
size_t layerIndex) const noexcept = 0;
963 virtual const
char* getStringByIndex(
size_t stringIndex) const noexcept = 0;
971 virtual
size_t getStringSizeByIndex(
size_t stringIndex) const noexcept = 0;
1037 virtual
size_t layerCount() const noexcept = 0;
1043 virtual
ILayer* getLayerByName(const
char* pLayerName) const noexcept = 0;
1130 virtual
NeuralResult mapLayerAsWeightsData(const
ILayer* pDataLayer, const
ILayer* pWeightsLayer, const
char* pWeightsName) noexcept = 0;
1155 const
char* pWeightsName,
1298 namespace common_categories
1545 typedef bool (*PrototypeRuntimeValidatorFunction)(
const INetwork* pNetwork);
1636 virtual const
ActivationDesc* exportedActivationByIndex(std::
size_t index) const noexcept = 0;
1639 virtual std::
size_t exportedLayersCount() const noexcept = 0;
1646 virtual const
LayerDesc* exportedLayerByIndex(std::
size_t index) const noexcept = 0;
1649 virtual std::
size_t exportedFusingRulesCount() const noexcept = 0;
1656 virtual const
FusingRule* exportedFusingRuleByIndex(std::
size_t index) const noexcept = 0;
1659 virtual std::
size_t exportedPrototypesCount() const noexcept = 0;
1666 virtual const
PrototypeDesc* exportedPrototypeByIndex(std::
size_t index) const noexcept = 0;
1673 virtual PrototypeRuntimeValidatorFunction exportedPrototypeRuntimeValidatorByIndex(std::
size_t index) const noexcept = 0;
1688 virtual
bool isPrototypeRuntimeCompatible(const
char* pPrototypeObjectClass, const
INetwork* pNetwork) const = 0;
1791 virtual std::size_t
height() const noexcept = 0;
1794 virtual std::
size_t width() const noexcept = 0;
1797 virtual std::
size_t channels() const noexcept = 0;
1802 virtual std::
size_t elements() const noexcept = 0;
1807 virtual std::uint8_t* data() noexcept = 0;
1810 virtual const std::uint8_t* data() const noexcept = 0;
@ Tensor
This order is used for parameters that typically describe tensor dimensions.
MemorySemantic
Describes the intended purpose of allocated GPU memory.
Definition: CoreTypes.h:629
@ Ephemeral
Memory used for short-lived scratch computations.
@ Unspecified
Generic allocation type, not tagged for any specific use.
@ Weights
Memory used for weights data; typically long-lived.
constexpr bool failed(NeuralResult result) noexcept
Helper function akin to COM's FAILED() macro.
Definition: CoreTypes.h:287
const std::uint32_t ApiVersion
API version set.
Definition: CoreTypes.h:51
TensorDataType
Enumeration describing common tensor element types.
Definition: CoreTypes.h:59
@ Float
32-bit floating point elements (float)
@ CompressedPng
NV Internal: Used to transit png like tensor between host and inference target.
@ CustomBase
Custom entries in this enum should use IDs numerically higher than this value.
@ Invalid
Invalid value used to guard against uninitialized variables.
@ TestOnly
Only used in a testing environment.
@ Half
16-bit floating point elements (__half)
ImageSpace
ImageSpace values refer to specific tensor representations of image data.
Definition: CoreTypes.h:298
@ RgbNormalized
RGB normalized to unit range; range is [0, 1].
@ RgbCentered
RGB centered around 0; range is [-1, 1].
TensorDataLayout
Enumeration describing common tensor data layouts.
Definition: CoreTypes.h:75
LayerInputType
This enum describes what type a particular input is for the layer.
Definition: CoreTypes.h:1326
@ Primary
Most inputs are "primary" inputs.
@ Secondary
Represents an input that is typically provided by the weights system.
@ PrimaryInfinite
Layers like concat and element_wise can take arbitrary numbers of inputs. Define one of these.
MemoryHandle__type * MemoryHandle
Opaque typedef used to represent INetworkBackend memory handles.
Definition: CoreTypes.h:624
constexpr bool succeeded(NeuralResult result) noexcept
Helper function akin to COM's SUCCEEDED() macro.
Definition: CoreTypes.h:282
NetworkBackendId
Enumeration describing common network backends.
Definition: CoreTypes.h:237
@ Cpu
Pure CPU code, no GPU involvement (largely unused)
@ Cuda
CUDA/cuDNN backend.
ParamType
This enum describes what type a particular parameter.
Definition: CoreTypes.h:1169
@ MaxParam
Should also be the next number for new non-custom types.
CompilationLevel
This enum represent kernel type contained by a prototype layer.
Definition: CoreTypes.h:1496
@ JitIntermediate
Examples: PTX, SPIR-V, or a compiled HLSL shader.
@ CompiledBinary
Example: SASS.
@ JitSource
Examples: CUDA C++, GLSL, or HLSL.
ActivationFunctionId
Enumeration describing common activation functions.
Definition: CoreTypes.h:257
@ LeakySigmoid
Leaky sigmoid ([0] = negative slope, [1] = positive slope)
@ Sine
Sine (also known as SIREN)
@ LeakyTanh
Leaky tanh ([0] = negative slope, [1] = positive slope)
@ LeakyReLU
Leaky ReLU ([0] = slope)
@ Tanh
Hyperbolic tangent.
@ ReLU
ReLU ([0] = minimum value to return)
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:273
@ Success
Operation succeeded. Generic result.
@ Unsupported
Operation failed and will not pass on a retry (not implemented or logic error).
@ Failure
Operation failed. Generic result.
Float16 is a CPU-side implementation of half-precision floating point (aka FP16).
Definition: CoreTypes.h:199
Float16()=default
Default constructor, initializes to zero.
Float16 & operator=(double value)
Assignment operator from float/double.
Definition: CoreTypes.h:214
std::uint16_t data
Sized integer containing the float16 value.
Definition: CoreTypes.h:202
IActivationFunction represents a functor that can perform a specific activation function.
Definition: CoreTypes.h:1823
virtual const char * serializedType() const noexcept=0
Retrieves the type of the activation function.
virtual NeuralResult setNetworkRuntime(INetworkRuntime *pNetwork) noexcept=0
Sets the owning network runtime. Will be called before any call to invoke.
virtual NeuralResult invoke(ILayer *pLayer) noexcept=0
Performs activation for a layer.
The IApiVersionQuery interface provides this object's compiled-in ApiVersion.
Definition: CoreTypes.h:481
virtual std::uint32_t apiVersion() const noexcept=0
Returns the value of ApiVersion used to build this object.
IBackendDeviceIdentifier is an opaque identifier for an active GPU.
Definition: CoreTypes.h:601
virtual const char * getDeviceName() const noexcept=0
Retrieves the name of this GPU.
virtual NeuralResult getDeviceIdentifiers(std::uint64_t *pUuidLow, std::uint64_t *pUuidHigh) const noexcept=0
Retrieves a pair of values that uniquely identify this GPU on the local system.
Common class registry for instantiating objects and collecting plugin-provided descriptors.
Definition: CoreTypes.h:1609
virtual NeuralResult importPluginLoader(IPluginLoader *pPluginLoader)=0
Imports all plugins loaded by a plugin loader.
virtual NeuralResult importPlugin(IPlugin *pPlugin)=0
Imports everything (layer, activation, fusing rules, and prototypes) registered with a single plugin.
virtual std::size_t exportedActivationsCount() const noexcept=0
Returns the count of registered activation functions.
IImage represents a bitmap image in system memory.
Definition: CoreTypes.h:1780
virtual std::size_t height() const noexcept=0
Returns the height of the image in pixels.
virtual NeuralResult resize(std::size_t height, std::size_t width, std::size_t channels) noexcept=0
Clears the image and reserves storage.
ILayer is the base class for neural network layers.
Definition: LayerTypes.h:59
ILayerList represents an immutable collection of ILayer pointers.
Definition: CoreTypes.h:927
virtual size_t layerCount() const noexcept=0
Returns the number of layers in this collection.
ILibraryContext is a generic library handle wrapper.
Definition: CoreTypes.h:569
std::uint64_t LibraryId
Library IDs should be generated randomly similar to interface IDs.
Definition: CoreTypes.h:575
virtual LibraryId libraryId() const noexcept=0
Retrieves a stable identifier for the library being tracked in this object.
Logger interface class.
Definition: CoreTypes.h:412
virtual VerbosityLevel verbosity() const noexcept=0
Retrieves the current verbosity level.
std::int32_t VerbosityLevel
Typedef for verbosity levels.
Definition: CoreTypes.h:422
INetworkBackend is a runtime-specific interface for CUDA, DirectX, or other system- specific operatio...
Definition: CoreTypes.h:641
virtual bool supportsOptimization(OptimizationCapability optimization) const noexcept=0
Returns true if the indicated optimization is applicable to this backend.
virtual const IBackendDeviceIdentifier * deviceIdentifier() const noexcept=0
Retrieves an opaque device identifier object corresponding to the device associated with this backend...
virtual NeuralResult initializeFromDeviceIdentifier(const IBackendDeviceIdentifier *pDeviceIdentifier) noexcept=0
Initializes the backend to point to a specific device identifier.
OptimizationCapability
List of optional optimizations supported by backends.
Definition: CoreTypes.h:661
virtual NeuralResult initializeFromDeviceOrdinal(std::uint32_t deviceOrdinal) noexcept=0
Initializes the backend to point to a specific device ordinal.
INetworkDebugger defines a callback interface for network inference.
Definition: NetworkTypes.h:51
INetworkDebuggerList represents an immutable collection of INetworkDebugger pointers.
Definition: CoreTypes.h:978
virtual size_t debuggerCount() const noexcept=0
INetwork is the public interface to Network.
Definition: NetworkTypes.h:119
INetworkRuntime is a subset of the basic network interface that is accessible from layer classes duri...
Definition: CoreTypes.h:996
virtual const char * networkName() const noexcept=0
Retrieves the name of this network as a UTF-8 string.
Represents a serialized parameter block in a model definition.
Definition: CoreTypes.h:1697
virtual NeuralResult setInteger(const char *pParameterName, std::int32_t value) noexcept=0
Saves an integer.
virtual NeuralResult getString(const char *pParameterName, const char **pStringOut) const noexcept=0
Retrieves a UTF-8 string value.
virtual NeuralResult setString(const char *pParameterName, const char *pString) noexcept=0
Saves a UTF-8 string value.
virtual NeuralResult getSize(const char *pParameterName, std::size_t *pSizeOut) const noexcept=0
Retrieves an unsigned integer value that can represent the result of sizeof().
virtual NeuralResult setFloat(const char *pParameterName, float value) noexcept=0
Saves a floating-point value.
virtual NeuralResult getFloat(const char *pParameterName, float *pFloatOut) const noexcept=0
Retrieves a floating-point value.
virtual NeuralResult getDimension(const char *pParameterName, TensorDimension *pDimOut) const noexcept=0
Retrieves a tensor dimension.
virtual NeuralResult setSize(const char *pParameterName, std::size_t value) noexcept=0
Saves an unsigned integer that can represent the result of sizeof().
virtual NeuralResult setDimension(const char *pParameterName, TensorDimension value) noexcept=0
Saves a tensor dimension.
virtual NeuralResult getInteger(const char *pParameterName, std::int32_t *pIntOut) const noexcept=0
Retrieves a signed integer value.
IPlugin is the general factory interface used by NvNeural's plugin system.
Definition: PluginTypes.h:41
Platform-agnostic plugin loader interface.
Definition: PluginTypes.h:200
Base class for all objects, similar to COM's IUnknown.
Definition: CoreTypes.h:341
virtual void * queryInterface(TypeId interface) noexcept=0
Retrieves a new object interface pointer.
static const TypeId typeID
Interface TypeId for InterfaceOf purposes.
Definition: CoreTypes.h:350
std::uint64_t TypeId
Every interface must define a unique TypeId. This should be randomized.
Definition: CoreTypes.h:347
std::uint32_t RefCount
Typedef used to track the number of active references to an object.
Definition: CoreTypes.h:344
virtual RefCount addRef() const noexcept=0
Increments the object's reference count.
virtual RefCount release() const noexcept=0
Decrements the object's reference count and destroy the object if the reference count reaches zero.
IRuntimeOptionsHost is an interface that provides runtime option communication from the layer to the ...
Definition: CoreTypes.h:542
virtual NeuralResult optionsRefreshed(const ILayer *pLayer) noexcept=0
Layers should call this when the options have changed, but not when the value for the option has chan...
IStringList represents an immutable collection of strings.
Definition: CoreTypes.h:946
virtual size_t stringCount() const noexcept=0
IWeightsData represents a binary buffer provided by IWeightsLoader.
Definition: CoreTypes.h:492
virtual NetworkBackendId backendId() const noexcept=0
Returns the backend for which this weights data is relevant.
IWeightsLoader is an interface that provides weights to layers.
Definition: CoreTypes.h:523
virtual NeuralResult getWeightsForLayer(IWeightsData **ppWeightsDataOut, const INetworkRuntime *pNetwork, const ILayer *pLayer, const char *pName) const noexcept=0
Retrieves a weights data buffer in a canonical format.
const char *const Analysis
Category for visualization and analysis layers.
Definition: CoreTypes.h:1311
const char *const Examples
Category for demonstration layers.
Definition: CoreTypes.h:1307
const char *const DataImageProcessing
Category for layers that do image processing.
Definition: CoreTypes.h:1308
const char *const Fused
Category for layers that fuse multiple operations.
Definition: CoreTypes.h:1306
const char *const Training
Category for layers that represent training-only concepts.
Definition: CoreTypes.h:1302
const char *const Shape
Category for layers that adjust tensor shape.
Definition: CoreTypes.h:1304
const char *const InputOutput
Category for layers that interact with their host application.
Definition: CoreTypes.h:1301
const char *const DevelopmentAids
Category for layers that aid framework development.
Definition: CoreTypes.h:1310
const char *const DefaultHidden
Category for layers that should be hidden in the editor by default.
Definition: CoreTypes.h:1312
const char *const General
Category for layers that don't fit other categories.
Definition: CoreTypes.h:1300
const char *const Upsampling
Category for layers that upscale their input.
Definition: CoreTypes.h:1305
const char *const DomainSpecific
Category for layers that implement specialized operations.
Definition: CoreTypes.h:1309
const char *const FormatConversion
Category for layers that permute and shuffle data.
Definition: CoreTypes.h:1303
Structure describing an activation function (IActivationFunction) for tool interfaces and network bui...
Definition: CoreTypes.h:1442
std::size_t structSize
This is the sizeof() this struct.
Definition: CoreTypes.h:1446
ActivationFunctionId activationFunction
This is the activation function ID implemented by this activation function.
Definition: CoreTypes.h:1471
std::size_t numParameters
This is the number of parameters supported for this activation.
Definition: CoreTypes.h:1486
TensorFormat tensorFormat
This is the tensor format supported by this activation function.
Definition: CoreTypes.h:1482
NetworkBackendId backend
This is the backend identifier supported by this instance of the activation function.
Definition: CoreTypes.h:1478
const char * pDocumentation
An optional human-readable descriptive text.
Definition: CoreTypes.h:1461
const ParamDesc * pParameters
This is the pointer to the contiguous memory of ParamDesc structs.
Definition: CoreTypes.h:1491
const char * pSerializedName
This is the name used to represent the activation function in serialized form.
Definition: CoreTypes.h:1457
const char * pObjectClass
This is the programmatic class name used to instantiate the activation object through the IPlugin::cr...
Definition: CoreTypes.h:1452
const char * pDisplayName
An optional human-readable layer name.
Definition: CoreTypes.h:1468
For implementers, this struct needs to be replicated in each xParamTypeDesc right now.
Definition: CoreTypes.h:1184
ParamType paramType
This for additional safety and reference. Should replicate the xParamDesc::paramType.
Definition: CoreTypes.h:1190
std::size_t structSize
This is the sizeof() the xParamTypeDesc struct that contains this struct.
Definition: CoreTypes.h:1187
The DimensionParamTypeDesc further describes a parameter for the plugin and is pointed to from the hi...
Definition: CoreTypes.h:1204
std::size_t minDimensions
This is the minimum amount of dimensions that are needed.
Definition: CoreTypes.h:1212
BaseParamTypeDesc baseDesc
This is the base param desc struct which all xParamTypeDesc must have.
Definition: CoreTypes.h:1206
std::size_t maxDimensions
This is the maximum amount of dimensions that are valid.
Definition: CoreTypes.h:1209
The EnumParamTypeDesc further describes a parameter for the plugin and is pointed to from the higher ...
Definition: CoreTypes.h:1226
BaseParamTypeDesc baseDesc
This is the base param desc struct which all xParamTypeDesc must have.
Definition: CoreTypes.h:1228
const char *const * pOptions
This is the array of the enums with optionCount members.
Definition: CoreTypes.h:1237
std::size_t optionCount
This is the amount of enum options contained in the memory block.
Definition: CoreTypes.h:1231
Defines a fusing rule that can be applied during model loading.
Definition: CoreTypes.h:1589
std::uint32_t syntaxVersion
This is the version number of the fusing rule grammar.
Definition: CoreTypes.h:1592
const char * pFusingRule
This is the fusing rule text, encoded in UTF-8.
Definition: CoreTypes.h:1596
Helper template to aid retrieval of interface IDs.
Definition: CoreTypes.h:401
This structure describes an ILayer for tools and network builders.
Definition: CoreTypes.h:1362
NetworkBackendId backend
This is the backend identifier supported by this instance of the layer type.
Definition: CoreTypes.h:1405
const char * pObjectClass
This is the programmatic class name used to instantiate the layer object through the IPlugin::createO...
Definition: CoreTypes.h:1374
std::size_t numCategories
This is the number of categories.
Definition: CoreTypes.h:1395
bool generatesOutput
Describes whether the primary output from this layer generates output.
Definition: CoreTypes.h:1422
const ParamDesc * pParameters
This is the pointer to the array of ParamDesc structs.
Definition: CoreTypes.h:1434
const char * pDisplayName
An optional human-readable layer name.
Definition: CoreTypes.h:1391
std::size_t numInputs
This is the number of inputs supported by this layer.
Definition: CoreTypes.h:1414
const LayerInputDesc * pInputs
This is a pointer to the array of LayerInputDesc structs which define the inputs to this layer.
Definition: CoreTypes.h:1419
TensorFormat tensorFormat
This is a tensor format supported by this instance of the layer type.
Definition: CoreTypes.h:1410
const char * pDocumentation
An optional human-readable descriptive text.
Definition: CoreTypes.h:1386
const char * pSerializedName
This is the name used to represent the layer type in serialized form.
Definition: CoreTypes.h:1380
const char *const * ppCategories
An optional array of strings which denote categories that the host can use to organize this layer.
Definition: CoreTypes.h:1400
std::size_t numParameters
This is the number of parameters supported for this layer.
Definition: CoreTypes.h:1428
std::size_t structSize
This is the sizeof() this struct.
Definition: CoreTypes.h:1366
ParamDesc describes a parameter for the plugin, giving it a name, default value, type,...
Definition: CoreTypes.h:1258
ParamType paramType
This is a enum that describes this parameter.
Definition: CoreTypes.h:1277
const BaseParamTypeDesc * pParamTypeDetails
This is an optional struct that give greater detail to the paramType if needed, for instance,...
Definition: CoreTypes.h:1289
std::size_t structSize
This is the sizeof() this struct. It is used for versioning.
Definition: CoreTypes.h:1260
const char * pName
This is the name of the parameter, usually a friendly name.
Definition: CoreTypes.h:1266
const char * pDefault
This is the default value of the parameter.
Definition: CoreTypes.h:1272
const char * pDocumentation
An optional human-readable descriptive text.
Definition: CoreTypes.h:1283
This structure represent a prototype layer version (backend, tensor format and kernel type),...
Definition: CoreTypes.h:1505
TensorFormat tensorFormat
This is the tensor format supported by this prototype layer.
Definition: CoreTypes.h:1534
const char * pSerializedName
This is the name used to represent the prototype type in serialized form.
Definition: CoreTypes.h:1521
NetworkBackendId backend
This is the backend identifier supported by this instance of the prototype layer.
Definition: CoreTypes.h:1531
std::size_t structSize
This is the sizeof() this struct.
Definition: CoreTypes.h:1509
CompilationLevel compilationLevel
This is the compilation level of the contained kernel.
Definition: CoreTypes.h:1537
const char * pObjectClass
This is the programmatic class name used to instantiate the prototype object through the IPlugin::cre...
Definition: CoreTypes.h:1515
const char * pDisplayName
An optional human-readable prototype name.
Definition: CoreTypes.h:1526
The StringParamTypeDesc further describes a parameter for the plugin and is pointed to from the highe...
Definition: CoreTypes.h:1245
bool supportsMultilineTextbox
This is a UI hint for the size of the text box of the string.
Definition: CoreTypes.h:1251
BaseParamTypeDesc baseDesc
This is the base param desc struct which all xParamTypeDesc must have.
Definition: CoreTypes.h:1247
TensorDimension describes the dimensions of a four-dimensional image tensor.
Definition: CoreTypes.h:134
size_t c
C dimension (channel)
Definition: CoreTypes.h:136
TensorDimension & operator=(const TensorDimension ©From)
Copy assignment operator.
Definition: CoreTypes.h:165
bool operator!=(const TensorDimension &other) const
Inequality operator.
Definition: CoreTypes.h:181
size_t h
H dimension (height)
Definition: CoreTypes.h:137
~TensorDimension()=default
Trivial destructor.
TensorDimension()=default
Default constructor. Initializes all members to zero.
TensorDimension(size_t N, size_t C, size_t H, size_t W)
Direct constructor, specifying all members at once.
Definition: CoreTypes.h:144
size_t w
W dimension (width)
Definition: CoreTypes.h:138
bool operator==(const TensorDimension &other) const
Equality operator.
Definition: CoreTypes.h:175
TensorDimension(const TensorDimension ©From)
Copy constructor.
Definition: CoreTypes.h:156
std::size_t elementCount() const
Returns the number of elements in a tensor with these dimensions.
Definition: CoreTypes.h:188
size_t n
N dimension (batch)
Definition: CoreTypes.h:135