Skip to content

Commit

Permalink
[ GPU/OpenCL ] change addition_layer_cl to inherit LayerImplCl
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
EunjuYang committed Dec 2, 2024
1 parent 4b6776b commit aeddb45
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 5 additions & 3 deletions nntrainer/cl_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ static void add_default_object(ClContext &cc) {
ml::train::LayerType::LAYER_FC);
}

cc.registerFactory(nntrainer::createLayer<AdditionLayerCL>,
AdditionLayerCL::type,
ml::train::LayerType::LAYER_ADDITION);
if (AdditionLayerCL::registerClKernels()) {
cc.registerFactory(nntrainer::createLayer<AdditionLayerCL>,
AdditionLayerCL::type,
ml::train::LayerType::LAYER_ADDITION);
}

// @todo swiglulayercl also needs to be updated.
cc.registerFactory(nntrainer::createLayer<SwiGLULayerCl>, SwiGLULayerCl::type,
Expand Down
19 changes: 15 additions & 4 deletions nntrainer/layers/cl_layers/addition_layer_cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
#include <cl_context.h>
#include <common_properties.h>
#include <layer_devel.h>
#include <layer_impl_cl.h>

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
Expand Down Expand Up @@ -93,10 +94,20 @@ class AdditionLayerCL : public Layer {
*/
const std::string getType() const override { return AdditionLayerCL::type; };

std::tuple<props::Print>
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<props::Print>
add_props; /**< fc layer properties : unit - number of output neurons */
};

} // namespace nntrainer
Expand Down

0 comments on commit aeddb45

Please sign in to comment.