#ifndef NCNN_LAYER_H
#define NCNN_LAYER_H
#include "mat.h"
#include "modelbin.h"
#include "option.h"
#include "paramdict.h"
#include "platform.h"
#if NCNN_VULKAN
#include "command.h"
#include "pipeline.h"
#endif
namespace ncnn {
class NCNN_EXPORT Layer
{
public:
Layer();
virtual ~Layer();
virtual int load_param(const ParamDict& pd);
virtual int load_model(const ModelBin& mb);
virtual int create_pipeline(const Option& opt);
virtual int destroy_pipeline(const Option& opt);
public:
bool one_blob_only;
bool support_inplace;
bool support_vulkan;
bool support_packing;
bool support_bf16_storage;
bool support_fp16_storage;
bool support_int8_storage;
bool support_image_storage;
bool support_tensor_storage;
bool support_reserved_00;
bool support_reserved_0;
bool support_reserved_1;
bool support_reserved_2;
bool support_reserved_3;
bool support_reserved_4;
bool support_reserved_5;
bool support_reserved_6;
bool support_reserved_7;
bool support_reserved_8;
bool support_reserved_9;
int featmask;
public:
virtual int forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_blobs, const Option& opt) const;
virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
virtual int forward_inplace(std::vector<Mat>& bottom_top_blobs, const Option& opt) const;
virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
#if NCNN_VULKAN
public:
virtual int upload_model(VkTransfer& cmd, const Option& opt);
public:
virtual int forward(const std::vector<VkMat>& bottom_blobs, std::vector<VkMat>& top_blobs, VkCompute& cmd, const Option& opt) const;
virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
virtual int forward(const std::vector<VkImageMat>& bottom_blobs, std::vector<VkImageMat>& top_blobs, VkCompute& cmd, const Option& opt) const;
virtual int forward(const VkImageMat& bottom_blob, VkImageMat& top_blob, VkCompute& cmd, const Option& opt) const;
virtual int forward_inplace(std::vector<VkMat>& bottom_top_blobs, VkCompute& cmd, const Option& opt) const;
virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
virtual int forward_inplace(std::vector<VkImageMat>& bottom_top_blobs, VkCompute& cmd, const Option& opt) const;
virtual int forward_inplace(VkImageMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
public:
const VulkanDevice* vkdev;
#endif
public:
void* userdata;
int typeindex;
#if NCNN_STRING
std::string type;
std::string name;
#endif
std::vector<int> bottoms;
std::vector<int> tops;
std::vector<Mat> bottom_shapes;
std::vector<Mat> top_shapes;
};
typedef Layer* (*layer_creator_func)(void*);
typedef void (*layer_destroyer_func)(Layer*, void*);
struct layer_registry_entry
{
#if NCNN_STRING
const char* name;
#endif
layer_creator_func creator;
};
struct custom_layer_registry_entry
{
#if NCNN_STRING
const char* name;
#endif
layer_creator_func creator;
layer_destroyer_func destroyer;
void* userdata;
};
struct overwrite_builtin_layer_registry_entry
{
int typeindex;
layer_creator_func creator;
layer_destroyer_func destroyer;
void* userdata;
};
#if NCNN_STRING
NCNN_EXPORT int layer_to_index(const char* type);
NCNN_EXPORT Layer* create_layer(const char* type);
NCNN_EXPORT Layer* create_layer_naive(const char* type);
NCNN_EXPORT Layer* create_layer_cpu(const char* type);
#if NCNN_VULKAN
NCNN_EXPORT Layer* create_layer_vulkan(const char* type);
#endif
#endif
NCNN_EXPORT Layer* create_layer(int index);
NCNN_EXPORT Layer* create_layer_naive(int index);
NCNN_EXPORT Layer* create_layer_cpu(int index);
#if NCNN_VULKAN
NCNN_EXPORT Layer* create_layer_vulkan(int index);
#endif
#define DEFINE_LAYER_CREATOR(name) \
::ncnn::Layer* name##_layer_creator(void* ) \
{ \
return new name; \
}
#define DEFINE_LAYER_DESTROYER(name) \
void name##_layer_destroyer(::ncnn::Layer* layer, void* ) \
{ \
delete layer; \
}
}
#endif