Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GPU/OpenCL] Initial version of FC Layer with OpenCL ops #2570

Merged
merged 6 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion api/ccapi/include/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,21 @@ Input(const std::vector<std::string> &properties = {}) {
/**
* @brief Helper function to create fully connected layer
*/
inline std::unique_ptr<Layer> FullyConnected(
inline std::unique_ptr<Layer>
FullyConnected(const std::vector<std::string> &properties = {}) {
return createLayer(LayerType::LAYER_FC, properties);
}

#ifdef ENABLE_OPENCL
/**
* @brief Helper function to create fully connected layer for GPU
*/
inline std::unique_ptr<Layer> FullyConnectedCl(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not this PR, but how about create CL Layer with same interface with device options like cpu/gpu?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createLayer(const LayerType &type,
            const std::vector<std::string> &properties = {},
            const LayerComputeEngine &compute_engine = LayerComputeEngine::CPU);

This will set lnode->setComputeEngine(compute_engine); which can be used inside layer classes using RunLayerContext reference. We can use that to have conditions within a layer class instead of having separate class for CPU/GPU.

const std::vector<std::string> &properties = {},
const LayerComputeEngine &compute_engine = LayerComputeEngine::CPU) {
return createLayer(LayerType::LAYER_FC, properties, compute_engine);
}
#endif

/**
* @brief Helper function to create batch normalization layer
Expand Down
7 changes: 4 additions & 3 deletions nntrainer/cl_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

#include <cl_context.h>
#include <fc_layer.h>
#include <fc_layer_cl.h>

namespace nntrainer {

Expand All @@ -23,8 +23,9 @@ std::once_flag global_cl_context_init_flag;

static void add_default_object(ClContext &cc) {

cc.registerFactory(nntrainer::createLayer<FullyConnectedLayer>,
FullyConnectedLayer::type, ml::train::LayerType::LAYER_FC);
cc.registerFactory(nntrainer::createLayer<FullyConnectedLayerCl>,
FullyConnectedLayerCl::type,
ml::train::LayerType::LAYER_FC);
}

static void registerer(ClContext &cc) noexcept {
Expand Down
Loading