20 #include "../context.h"
22 #include "../gpu/linear_mapping.h"
23 #include "../gpu/program.h"
24 #include "../gpu/program_bank.h"
25 #include "../utils/chunkfile.h"
26 #include "../utils/progress_tracking.h"
27 #include "../utils/string_builder.h"
28 #include "../utils/listing.h"
103 Exception(
"Error when configuring '%s' operation: %s.",
op->
getName().c_str(), shortDescription)
107 Exception(
"Error when configuring '%s' operation: %s. Cannot convert %u bytes of the given weights to %u requested entries.",
108 op->
getName().c_str(), shortDescription, (unsigned int)sizeBytesGot, (unsigned int)entriesRequested)
221 virtual std::map<std::string, std::string>
serialize()
const = 0;
321 void sample(
StringBuilder& code,
const char* inputName,
const int inputIndex,
const Point&
shift,
const bool isFirstSample =
true,
const char* suffix =
"");
468 virtual void execute(
const int sliceStart,
const int sliceStop,
const int threadIdx,
const int threadCount) = 0;
A key-value pair set storing pieces of arbitrary data (chunks) under string keys.
Basic class: task and memory management, any kind of static data.
Base class for all exceptions.
Stores linked GLSL programs and their associated fragment shader codes.
Real-valued vector usable by GPU.
Internal low-level GPU control API.
Enables construction of an operation from its serialized representation.
Deserializer(const char *opType)
Registers a new deserializer capable of building an operation from a listing block.
static std::map< std::string, Deserializer * > & getDeserializersMap()
virtual AbstractOperation * deserialize(Context &context, const Listing::Block &block)=0
Constructs an operation from a serialized representation (a listing block).
InconsistentModelData(const AbstractOperation *op, const char *shortDescription)
InconsistentModelData(const AbstractOperation *op, const char *shortDescription, const size_t entriesRequested, const size_t sizeBytesGot)
NotReady(const AbstractOperation *op)
Abstract neural net operation (layer).
virtual int getOutputCount() const
Returns number of operation outputs.
virtual bool acceptsTextureInput(int index=0) const
Returns true if the operation can take a GL::TextureHandler at a specific input.
virtual bool acceptsStorageOutput(int index=0) const
Returns true if the operation can take a Storage::View at a specific output.
AbstractOperation(const AbstractOperation &)=delete
disabling copying constructor
virtual Size getOutputSize(int outputIndex=0) const
Returns full size of a specific operation output.
virtual bool acceptsVectorInput(int index=0) const
Returns true if the operation can take a GL::Vector at a specific input.
virtual void setInput(Storage::View &&storage, int index=0)
virtual std::map< std::string, std::string > serialize() const =0
Returns a serialized representation of th operation;.
virtual int getInputCount() const
Returns number of operation inputs.
virtual ~AbstractOperation()
virtual int getInputPadding(int index=0) const
Retrieves minimum required size of zero padding for a given input.
AbstractOperation(const std::string &name)
virtual void execute(TaskThread &thread, GraphicPipeline &gpu)=0
Executes the operation.
virtual void prepare(GraphicPipeline &gpu, ChunkCollection &data, GL::ProgramBank &bank)=0
Compiles GLSL shaders.
virtual bool acceptsStorageInput(int index=0) const
Returns true if the operation can take a Storage::View at a specific input.
virtual Storage::View getOutput(int index=0)
Returns a storage view bound to a specific operation output.
virtual unsigned long countMultiplyAdds() const
Counts (approximate) number of multiply-adds used by this operation.
virtual void setOutput(Storage::View &&storage, int index=0)
virtual bool acceptsVectorOutput(int index=0) const
Returns true if the operation can take a GL::Vector at a specific output.
virtual unsigned long countTexelFetches() const
Counts (approximate) number of texels fetches.
virtual bool usesGpu() const
Returns true if the operation is run on GPU.
virtual bool acceptsTextureOutput(int index=0) const
Returns true if the operation can take a GL::TextureHandler at a specific output.
std::string getName() const
virtual void execute(TaskThread &thread)
Executes the operation within a specific CPU thread.
virtual void disconnect()=0
Assigns empty inputs and outputs.
virtual void getSampledChannels(int index, int &min, int &max) const =0
Retrieves range of input features channels sampled at the same time for a specific input.
A mixin implementing activation functions in GLSL.
ActivationFunctionMixin(const ActivationFunction activationFunc)
const ActivationFunction activationFunc
void apply(StringBuilder &code, const char *inputVariable)
Renders a GLSL code applying activation function to a specific variable and writing the result to gl_...
Operation computed on CPU.
void execute(TaskThread &thread, GraphicPipeline &gpu)
Executes the operation.
void prepare(GraphicPipeline &gpu, ChunkCollection &data, GL::ProgramBank &bank)
Compiles GLSL shaders.
bool usesGpu() const
Returns true if the operation is run on GPU.
virtual void execute(const int sliceStart, const int sliceStop, const int threadIdx, const int threadCount)=0
Executes the operation body within a specific CPU thread.
virtual int getAmountOfWork() const =0
Returns amount of work in arbitrary units to be splitted among threads.
void getSampledChannels(int index, int &min, int &max) const
Retrieves range of input features channels sampled at the same time for a specific input.
virtual void beforeExecute(GraphicPipeline &gpu, const int threadCount)
Called right before the operation is executed.
CpuOperation(const std::string &name)
virtual void afterExecute(const int threadCount)
Called right after the operation is executed.
Operation 3D input/output size.
Padding
Zero padding specification.
Generates GLSL fragment shader code sampling a local neighborhood around the current texture coordina...
Rectangle getTextureCoordinates(const Storage::View &storage, const int channel, const IntPoint &stride, const Size::Padding padding, const IntPoint &outputSize) const
Computes texture coordinates sampling a specific storage channel for given stride,...
void sample(StringBuilder &code, const char *inputName, const int inputIndex, const Point &shift, const bool isFirstSample=true, const char *suffix="")
Samples a neighborhood of a given texture.
void sampleInline(StringBuilder &code, const char *inputName, const int inputIndex, const IntPoint &position, const Point &shift, const char *suffix="")
bool isUniformShiftUsed() const
void setup(const int width, const int height)
Prepares the spatial filtering operation execution.
static const char * SAMPLE_ID_PREFIX
prefix of variables declaring a neighbor sample
Point shift
current static shift of the sampling position
int getDeltasSize() const
void writeHeader(StringBuilder &code, bool useUniformShift)
Writes out the very GLSL fragment shader header required for spatial neighborhood sampling.
std::string getInputSamplingPos() const
Retrieves input sampling point position for the current fragment.
void declare(StringBuilder &code, const char *datatype, bool inlineSampling=false)
Declares GLSL fragment shader main(..) code part required for spatial neighborhood sampling.
void setupProgram(GL::Program &program)
Prepares a given program for spatial filtering.
IntRectangle getSamplingArea(const IntPoint &size, const IntPoint &stride, const Size::Padding padding) const
Implements common padding policies by computing a rectangular area of positions the sampling kernel t...
bool useUniformShift
if true, the sampling position can be shifted dynamically at every run
SpatialFilteringMixin(const int nbSizeX, const int nbSizeY)
Initializes spatial filtering mixin.
void setUniformShift(GL::Program &program, const IntPoint &shift, const IntPoint &inputSize)
Applies an offset to the sampling position at runtime.
float * deltas
array storing pixel position differences for neighborhood sampling
Maps a 3D tensor onto a storage.
Toolset to build a string content.
ActivationFunction activationFunctionFromString(const std::string &str)
Returns a zero padding value from a string.
ActivationFunction
Activation function specification.
@ SIGMOID_LIKE
piecewise-linear sigmoid approximation
@ DEFAULT
default activation: 0..1 bounded ReLU (identity clipped to 0..1 range)
@ BRELU6
0.167 times identity clipped to 0..1 range
std::string to_string(Beatmup::NNets::ActivationFunction function)
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
JNIEnv jobject jstring str