From aeddb45be8c8dc8ffd6fd134dfc121c692fdb81a Mon Sep 17 00:00:00 2001 From: Eunju Yang Date: Fri, 29 Nov 2024 15:04:30 +0900 Subject: [PATCH] [ GPU/OpenCL ] change addition_layer_cl to inherit LayerImplCl - This commit updates addition_layer_cl.cpp/h to inherit LayerImplCl. - This commit implements registerClKernels() of addition_layer_cl layer. - This commit update cl_context.cpp (applying addition_layer_cl's update) Self evaluation: Build test: [X]Passed [ ]Failed [ ]Skipped Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Eunju Yang --- nntrainer/cl_context.cpp | 8 +++++--- .../layers/cl_layers/addition_layer_cl.h | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/nntrainer/cl_context.cpp b/nntrainer/cl_context.cpp index b6c200792b..25c2d66c2b 100644 --- a/nntrainer/cl_context.cpp +++ b/nntrainer/cl_context.cpp @@ -39,9 +39,11 @@ static void add_default_object(ClContext &cc) { ml::train::LayerType::LAYER_FC); } - cc.registerFactory(nntrainer::createLayer, - AdditionLayerCL::type, - ml::train::LayerType::LAYER_ADDITION); + if (AdditionLayerCL::registerClKernels()) { + cc.registerFactory(nntrainer::createLayer, + AdditionLayerCL::type, + ml::train::LayerType::LAYER_ADDITION); + } // @todo swiglulayercl also needs to be updated. cc.registerFactory(nntrainer::createLayer, SwiGLULayerCl::type, diff --git a/nntrainer/layers/cl_layers/addition_layer_cl.h b/nntrainer/layers/cl_layers/addition_layer_cl.h index a2b8f55f67..eb2acd2604 100644 --- a/nntrainer/layers/cl_layers/addition_layer_cl.h +++ b/nntrainer/layers/cl_layers/addition_layer_cl.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace nntrainer { @@ -25,12 +26,12 @@ namespace nntrainer { * @class AdditionLayerCL * @brief Addition Layer */ -class AdditionLayerCL : public Layer { +class AdditionLayerCL : public LayerImplCl { public: /** * @brief Constructor of Addition Layer */ - AdditionLayerCL() : Layer(), add_props(props::Print()) {} + AdditionLayerCL() : LayerImplCl(), add_props(props::Print()) {} /** * @brief Destructor of Addition Layer @@ -93,10 +94,20 @@ class AdditionLayerCL : public Layer { */ const std::string getType() const override { return AdditionLayerCL::type; }; - std::tuple - add_props; /**< fc layer properties : unit - number of output neurons */ + /** + * @brief registerClKernels for addition_layer_cl + * @details registerClKernels for addition_layer_cl always returns true + * without any specific action for kernel registeration. It only uses + * cl_blas_kernels and there is no specific kernels for this. If there are + * specific kernels for this, it should be updated to register the kernels . + */ + static bool registerClKernels() { return true; }; inline static const std::string type = "addition"; + +private: + std::tuple + add_props; /**< fc layer properties : unit - number of output neurons */ }; } // namespace nntrainer