Skip to content

Commit

Permalink
no more virtual public
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui committed Jan 3, 2024
1 parent 6ba55bf commit fdc2226
Show file tree
Hide file tree
Showing 261 changed files with 309 additions and 269 deletions.
20 changes: 13 additions & 7 deletions cmake/ncnn_add_layer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ macro(ncnn_add_layer class)
source_group ("sources\\\\layers" FILES "${CMAKE_CURRENT_SOURCE_DIR}/layer/${name}.cpp")
endif()

if(WITH_LAYER_${name}_${NCNN_TARGET_ARCH})
set(layer_declaration "${layer_declaration}#include \"layer/${NCNN_TARGET_ARCH}/${name}_${NCNN_TARGET_ARCH}.h\"\n")
set(layer_declaration "${layer_declaration}namespace ncnn { DEFINE_LAYER_CREATOR(${class}_${NCNN_TARGET_ARCH}) }\n")

source_group ("sources\\\\layers\\\\${NCNN_TARGET_ARCH}" FILES "${CMAKE_CURRENT_SOURCE_DIR}/layer/${NCNN_TARGET_ARCH}/${name}_${NCNN_TARGET_ARCH}.cpp")
endif()

if(WITH_LAYER_${name}_vulkan)
set(layer_declaration "${layer_declaration}#include \"layer/vulkan/${name}_vulkan.h\"\n")
set(layer_declaration "${layer_declaration}namespace ncnn { DEFINE_LAYER_CREATOR(${class}_vulkan) }\n")
Expand All @@ -108,19 +115,18 @@ macro(ncnn_add_layer class)
source_group ("sources\\\\layers\\\\vulkan" FILES "${CMAKE_CURRENT_SOURCE_DIR}/layer/vulkan/${name}_vulkan.cpp")
endif()

if(WITH_LAYER_${name}_${NCNN_TARGET_ARCH})
set(layer_declaration "${layer_declaration}#include \"layer/${NCNN_TARGET_ARCH}/${name}_${NCNN_TARGET_ARCH}.h\"\n")
set(layer_declaration "${layer_declaration}namespace ncnn { DEFINE_LAYER_CREATOR(${class}_${NCNN_TARGET_ARCH}) }\n")

source_group ("sources\\\\layers\\\\${NCNN_TARGET_ARCH}" FILES "${CMAKE_CURRENT_SOURCE_DIR}/layer/${NCNN_TARGET_ARCH}/${name}_${NCNN_TARGET_ARCH}.cpp")
endif()

if(WITH_LAYER_${name})
set(layer_registry "${layer_registry}#if NCNN_STRING\n{\"${class}\", ${class}_layer_creator},\n#else\n{${class}_layer_creator},\n#endif\n")
else()
set(layer_registry "${layer_registry}#if NCNN_STRING\n{\"${class}\", 0},\n#else\n{0},\n#endif\n")
endif()

if(WITH_LAYER_${name}_${NCNN_TARGET_ARCH})
set(layer_registry_arch "${layer_registry_arch}#if NCNN_STRING\n{\"${class}\", ${class}_${NCNN_TARGET_ARCH}_layer_creator},\n#else\n{${class}_${NCNN_TARGET_ARCH}_layer_creator},\n#endif\n")
else()
set(layer_registry_arch "${layer_registry_arch}#if NCNN_STRING\n{\"${class}\", 0},\n#else\n{0},\n#endif\n")
endif()

if(WITH_LAYER_${name}_vulkan)
set(layer_registry_vulkan "${layer_registry_vulkan}#if NCNN_STRING\n{\"${class}\", ${class}_vulkan_layer_creator},\n#else\n{${class}_vulkan_layer_creator},\n#endif\n")
else()
Expand Down
28 changes: 28 additions & 0 deletions src/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ Layer* create_layer(const char* type)
return create_layer(index);
}

Layer* create_layer_naive(const char* type)
{
int index = layer_to_index(type);
if (index == -1)
return 0;

return create_layer_naive(index);
}

Layer* create_layer_cpu(const char* type)
{
int index = layer_to_index(type);
Expand Down Expand Up @@ -472,6 +481,20 @@ Layer* create_layer(int index)
return layer_final;
}

Layer* create_layer_naive(int index)
{
if (index < 0 || index >= layer_registry_entry_count)
return 0;

layer_creator_func layer_creator = layer_registry[index].creator;
if (!layer_creator)
return 0;

Layer* layer = layer_creator(0);
layer->typeindex = index;
return layer;
}

Layer* create_layer_cpu(int index)
{
if (index < 0 || index >= layer_registry_entry_count)
Expand Down Expand Up @@ -529,6 +552,11 @@ Layer* create_layer_cpu(int index)
}
else
#endif // NCNN_RUNTIME_CPU && NCNN_RVV
{
layer_creator = layer_registry_arch[index].creator;
}

if (!layer_creator)
{
layer_creator = layer_registry[index].creator;
}
Expand Down
2 changes: 2 additions & 0 deletions src/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,15 @@ struct overwrite_builtin_layer_registry_entry
NCNN_EXPORT int layer_to_index(const char* type);
// create layer from type name
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 // NCNN_VULKAN
#endif // NCNN_STRING
// create layer from layer type
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);
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/absval_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class AbsVal_arm : virtual public AbsVal
class AbsVal_arm : public AbsVal
{
public:
AbsVal_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/batchnorm_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class BatchNorm_arm : virtual public BatchNorm
class BatchNorm_arm : public BatchNorm
{
public:
BatchNorm_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/bias_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Bias_arm : virtual public Bias
class Bias_arm : public Bias
{
public:
virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/binaryop_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class BinaryOp_arm : virtual public BinaryOp
class BinaryOp_arm : public BinaryOp
{
public:
BinaryOp_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/cast_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Cast_arm : virtual public Cast
class Cast_arm : public Cast
{
public:
Cast_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/clip_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Clip_arm : virtual public Clip
class Clip_arm : public Clip
{
public:
Clip_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/concat_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Concat_arm : virtual public Concat
class Concat_arm : public Concat
{
public:
Concat_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/convolution1d_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Convolution1D_arm : virtual public Convolution1D
class Convolution1D_arm : public Convolution1D
{
public:
Convolution1D_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/convolution_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Convolution_arm : virtual public Convolution
class Convolution_arm : public Convolution
{
public:
Convolution_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/convolutiondepthwise_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class ConvolutionDepthWise_arm : virtual public ConvolutionDepthWise
class ConvolutionDepthWise_arm : public ConvolutionDepthWise
{
public:
ConvolutionDepthWise_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/crop_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Crop_arm : virtual public Crop
class Crop_arm : public Crop
{
public:
Crop_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/deconvolution_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Deconvolution_arm : virtual public Deconvolution
class Deconvolution_arm : public Deconvolution
{
public:
Deconvolution_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/deconvolutiondepthwise_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class DeconvolutionDepthWise_arm : virtual public DeconvolutionDepthWise
class DeconvolutionDepthWise_arm : public DeconvolutionDepthWise
{
public:
DeconvolutionDepthWise_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/dequantize_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Dequantize_arm : virtual public Dequantize
class Dequantize_arm : public Dequantize
{
public:
Dequantize_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/dropout_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Dropout_arm : virtual public Dropout
class Dropout_arm : public Dropout
{
public:
Dropout_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/eltwise_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Eltwise_arm : virtual public Eltwise
class Eltwise_arm : public Eltwise
{
public:
Eltwise_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/flatten_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Flatten_arm : virtual public Flatten
class Flatten_arm : public Flatten
{
public:
Flatten_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/gelu_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class GELU_arm : virtual public GELU
class GELU_arm : public GELU
{
public:
GELU_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/gemm_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Gemm_arm : virtual public Gemm
class Gemm_arm : public Gemm
{
public:
Gemm_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/gru_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class GRU_arm : virtual public GRU
class GRU_arm : public GRU
{
public:
GRU_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/hardsigmoid_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class HardSigmoid_arm : virtual public HardSigmoid
class HardSigmoid_arm : public HardSigmoid
{
public:
HardSigmoid_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/hardswish_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class HardSwish_arm : virtual public HardSwish
class HardSwish_arm : public HardSwish
{
public:
HardSwish_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/innerproduct_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class InnerProduct_arm : virtual public InnerProduct
class InnerProduct_arm : public InnerProduct
{
public:
InnerProduct_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/instancenorm_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class InstanceNorm_arm : virtual public InstanceNorm
class InstanceNorm_arm : public InstanceNorm
{
public:
InstanceNorm_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/interp_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Interp_arm : virtual public Interp
class Interp_arm : public Interp
{
public:
Interp_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/lrn_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class LRN_arm : virtual public LRN
class LRN_arm : public LRN
{
public:
virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/lstm_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class LSTM_arm : virtual public LSTM
class LSTM_arm : public LSTM
{
public:
LSTM_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/matmul_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class MatMul_arm : virtual public MatMul
class MatMul_arm : public MatMul
{
public:
MatMul_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/mish_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Mish_arm : virtual public Mish
class Mish_arm : public Mish
{
public:
Mish_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/multiheadattention_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class MultiHeadAttention_arm : virtual public MultiHeadAttention
class MultiHeadAttention_arm : public MultiHeadAttention
{
public:
MultiHeadAttention_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/packing_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Packing_arm : virtual public Packing
class Packing_arm : public Packing
{
public:
Packing_arm();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/arm/padding_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace ncnn {

class Padding_arm : virtual public Padding
class Padding_arm : public Padding
{
public:
Padding_arm();
Expand Down
Loading

0 comments on commit fdc2226

Please sign in to comment.