25 #ifndef NVNEURAL_BASEPROTOTYPELAYER_H
26 #define NVNEURAL_BASEPROTOTYPELAYER_H
34 #include <Pugixml/pugixml.hpp>
45 refobj::Implements<ILayer>
46 , refobj::Implements<IPrototypeLayer>
47 , refobj::Implements<ICppCodeGenerationLayer>>
48 , detail::ScriptInterpretInterface<detail::AnyOperand>
62 const char*
name()
const noexcept
override;
191 const std::
string& currentImpl,
203 const std::
string& type,
206 const std::
string& dim,
207 const std::
string& impl) noexcept;
213 std::vector<detail::AnyOperand>
m_ops;
218 struct BasePrototypeLayerParameters
223 std::map<std::string, std::string> code;
225 std::string dimNCHWCalculation;
227 std::map<std::string, std::string> fwdEvalCall;
228 std::vector<std::string> parametersKey;
229 std::string currentImpl;
233 void setReal(detail::AnyOperand& v,
const std::string& str)
override;
234 void setInteger(detail::AnyOperand& v,
const std::string& str)
override;
235 void setBufferPointer(detail::AnyOperand& v,
const std::string& str,
int arg_index)
override;
236 void neg(detail::AnyOperand& v)
override;
237 void add(detail::AnyOperand& v, detail::AnyOperand& op)
override;
238 void sub(detail::AnyOperand& v, detail::AnyOperand& op)
override;
239 void mul(detail::AnyOperand& v, detail::AnyOperand& op)
override;
240 void div(detail::AnyOperand& v, detail::AnyOperand& op)
override;
241 void setRealOption(detail::AnyOperand& v,
const std::string& str)
override;
242 void setIntegerOption(detail::AnyOperand& v,
const std::string& str)
override;
243 void transform(detail::AnyOperand& v,
const std::string& str)
override;
244 void setActType(detail::AnyOperand& v)
override;
245 void setActAlhpaLeft(detail::AnyOperand& v)
override;
246 void setActAlhpaRight(detail::AnyOperand& v)
override;
247 void setWeightsPointer(detail::AnyOperand& v,
const std::string& str)
override;
248 void setInputPointer(detail::AnyOperand& v,
int index)
override;
249 void setInputDimValue(detail::AnyOperand& v,
int index,
const std::string& str)
override;
250 void setOutputPointer(detail::AnyOperand& v,
const std::string&
name)
override;
251 void setOutputDimValue(detail::AnyOperand& v,
const std::string&
name,
const std::string& str)
override;
253 void createScriptEngine();
254 std::vector<detail::AnyOperand> interpretFinalize(
const detail::SynParser::Node& node,
bool onReshape =
false);
256 BasePrototypeLayerParameters m_basePrototypeParameters;
260 std::map<std::string, std::string> m_parameters;
261 std::vector<ILayer*> m_inputLayers;
265 std::vector<float> m_activationCoefficients;
267 detail::ScriptEngine* m_pEngine =
nullptr;
269 std::vector<ILayer*> m_skip;
271 detail::SynParser::Node m_fwdSyntree;
272 size_t m_smemSize = 0;
276 std::size_t m_expectedInputCount = 0;
278 bool m_reshapeFailed =
true;
Definitions of C++ code generation interfaces exported by tools and plugins.
Fundamental NvNeural data types are declared here.
NetworkBackendId
Enumeration describing common network backends.
Definition: CoreTypes.h:239
CompilationLevel
This enum represent kernel type contained by a prototype layer.
Definition: CoreTypes.h:1688
ActivationFunctionId
Enumeration describing common activation functions.
Definition: CoreTypes.h:259
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:275
Common interfaces for prototype layers.
Interface types needed by layer objects.
WeightsQuery
WeightsQuery describes the different types of queries for weights data.
Definition: LayerTypes.h:39
Standard implementation for IRefObject-derived objects.
Internal helper classes for working with prototype layer scripts.
Base class for the CUDA prototype layers shipped with NvNeural.
Definition: BasePrototypeLayer.h:49
NeuralResult getInputLayers(ILayerList **ppInputLayers) const noexcept
Retrieves the inputs for this layer.
Definition: BasePrototypeLayer.cpp:467
detail::SizeValue m_grid
Preferred grid size in blocks.
Definition: BasePrototypeLayer.h:211
NeuralResult setWeightsName(const char *pWeightsName) noexcept
Sets the name used to identify this layer's weights.
Definition: BasePrototypeLayer.cpp:576
INetworkRuntime * m_pNetwork
Pointer to owning network.
Definition: BasePrototypeLayer.h:209
float activationCoefficient(std::size_t coefficientIndex) const noexcept
Retrieves the activation coefficient for the specified index.
Definition: BasePrototypeLayer.cpp:555
NeuralResult setNetworkRuntime(INetworkRuntime *pNetworkRuntime) noexcept
Informs the layer it has been attached to a new network.
Definition: BasePrototypeLayer.cpp:385
NeuralResult setBasePrototypeInfo(std::size_t inputsCount, const std::string &type, NetworkBackendId backend, const TensorFormat &format, const std::string &dim, const std::string &impl) noexcept
Stores implementation-agnostic details of the prototype layer.
Definition: BasePrototypeLayer.cpp:188
NeuralResult setActivationFunction(ActivationFunctionId activationFunction) noexcept
Sets the activation function attached to the layer.
Definition: BasePrototypeLayer.cpp:525
NetworkBackendId backendId() const noexcept
Returns the backend ID associated with this layer implementation.
Definition: BasePrototypeLayer.cpp:410
NeuralResult addPrototypeCode(const char *pName, const char *pCode) noexcept final
Adds a kernel definition for a particular tensor format and backend.
Definition: BasePrototypeLayer.cpp:207
TensorDimension stepping() const noexcept
Returns the internal storage stride consumed by this layer implementation.
Definition: BasePrototypeLayer.cpp:405
const char * weightsName() const noexcept
Retrieves the name used to identify this layer's weights.
Definition: BasePrototypeLayer.cpp:569
NeuralResult getCpuConstData(void *pOutBuffer, size_t bufferByteCount, size_t *pBytesCopied, TensorFormat format) const noexcept
Retrieves read-only CPU-side memory for the layer's output.
Definition: BasePrototypeLayer.cpp:615
size_t tensorBufferSize() const noexcept
Retrieve the size of the layer's output tensor buffer in bytes.
Definition: BasePrototypeLayer.cpp:432
NeuralResult generateLayerCpp(ICppCodeGenerationLayerHost *pHost) noexcept final
Generates C++ code to configure the layer.
Definition: BasePrototypeLayer.cpp:241
NeuralResult loadBasePrototypeInfo(NetworkBackendId backendId, const TensorFormat &format, CompilationLevel compilationLevel, const std::string ¤tImpl, const IParameterNode *pParameters)
Loads prototype information from a parameter node.
Definition: BasePrototypeLayer.cpp:68
TensorDimension weightsDimensions(const char *pWeightsName, WeightsQuery queryType) const noexcept
Retrieves the tensor dimension of a layer's named weight input.
Definition: BasePrototypeLayer.cpp:583
virtual NeuralResult implementationForward() noexcept=0
Implementation-specific logic for ILayer::evaluateForward.
detail::SizeValue m_block
Preferred block size in threads.
Definition: BasePrototypeLayer.h:210
size_t tensorInternalBufferSize() const noexcept
Retrieves the dimensions of the layer's output tensor as allocated internally.
Definition: BasePrototypeLayer.cpp:440
NeuralResult setAffected(bool affected) noexcept
Sets or clears the "affected" flag on a layer's output tensor.
Definition: BasePrototypeLayer.cpp:514
NeuralResult addForwardEvalCall(const char *pName, const char *pCall) noexcept final
Adds a call script for a particular tensor format and backend.
Definition: BasePrototypeLayer.cpp:218
NeuralResult setPermanent(bool permanent) noexcept
Sets or clears the "permanent" flag on a layer's output tensor.
Definition: BasePrototypeLayer.cpp:503
NeuralResult getData(void **ppOut, TensorFormat format, const ILayer *pRequestingLayer) noexcept
Retrieves device-side memory for the layer's output.
Definition: BasePrototypeLayer.cpp:590
const char * serializedType() const noexcept
Retrieves the layer type.
Definition: BasePrototypeLayer.cpp:337
NeuralResult setInputLayer(size_t index, ILayer *pLayer) noexcept
Sets an input layer by index.
Definition: BasePrototypeLayer.cpp:477
TensorFormat tensorFormat() const noexcept
Returns the tensor format consumed by this layer implementation.
Definition: BasePrototypeLayer.cpp:415
TensorDimension internalDimensions() const noexcept
Retrieves the dimensions of the layer's output tensor as allocated internally.
Definition: BasePrototypeLayer.cpp:425
std::vector< detail::AnyOperand > m_ops
Arguments to pass to the compiled entry point.
Definition: BasePrototypeLayer.h:213
bool isAffected() const noexcept
Returns the current status of the "affected" flag.
Definition: BasePrototypeLayer.cpp:520
NeuralResult reshape() noexcept
Initializes (or reinitializes) the layer implementation with the current set of parameters.
Definition: BasePrototypeLayer.cpp:655
bool isPermanent() const noexcept
Returns the current status of the "permanent" flag.
Definition: BasePrototypeLayer.cpp:509
ActivationFunctionId activationFunction() const noexcept
Retrieves the activation function attached to this layer.
Definition: BasePrototypeLayer.cpp:531
NeuralResult loadFromParameters(const IParameterNode *pParameters) noexcept
Loads layer parameters from a serialized key-value representation.
Definition: BasePrototypeLayer.cpp:448
NeuralResult evaluateForward() noexcept
Performs forward evaluation for this layer.
Definition: BasePrototypeLayer.cpp:758
NeuralResult addParameterKey(const char *pKey) noexcept final
Adds a named parameter to the layer.
Definition: BasePrototypeLayer.cpp:229
std::string m_selected_code
Source code for the currently selected implementation.
Definition: BasePrototypeLayer.h:214
NeuralResult setName(const char *pName) noexcept
Sets the layer name.
Definition: BasePrototypeLayer.cpp:368
virtual NeuralResult implementationReshape() noexcept=0
Implementation-specific logic for ILayer::reshape.
std::string m_entry
Name of compiled entry point (e.g., CUDA function name)
Definition: BasePrototypeLayer.h:215
const char * name() const noexcept
Retrieves the layer name.
Definition: BasePrototypeLayer.cpp:380
NeuralResult getConstData(const void **ppOut, TensorFormat format, const ILayer *pRequestingLayer) const noexcept
Retrieves read-only device-side memory for the layer's output.
Definition: BasePrototypeLayer.cpp:599
NeuralResult networkGenerationComplete() noexcept final
Indicates the entire network has been generated.
Definition: BasePrototypeLayer.cpp:332
TensorDimension dimensions() const noexcept
Retrieves the dimensions of the layer's output tensor.
Definition: BasePrototypeLayer.cpp:420
NeuralResult setActivationCoefficient(std::size_t coefficientIndex, float value) noexcept
Sets an activation coefficient.
Definition: BasePrototypeLayer.cpp:536
BasePrototypeLayer()
Creates a new BasePrototypeLayer object.
Definition: BasePrototypeLayer.cpp:53
Tool-supplied interface for C++ code generation.
Definition: CodeGenTypes.h:130
ILayer is the base class for neural network layers.
Definition: LayerTypes.h:59
ILayerList represents an immutable collection of ILayer pointers.
Definition: CoreTypes.h:1060
INetworkBackend is a runtime-specific interface for CUDA, DirectX, or other system- specific operatio...
Definition: CoreTypes.h:643
INetworkRuntime is a subset of the basic network interface that is accessible from layer classes duri...
Definition: CoreTypes.h:1129
Represents a serialized parameter block in a model definition.
Definition: CoreTypes.h:1889
TensorDimension describes the dimensions of a four-dimensional image tensor.
Definition: CoreTypes.h:136
Parameterized base class implementing common IRefObject operations.
Definition: RefObject.h:336