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] OpenCL pipeline for layer execution on GPU @open sesame 03/07 10:42 #2465

Merged
merged 11 commits into from
Mar 7, 2024

Conversation

s-debadri
Copy link
Contributor

@s-debadri s-debadri commented Feb 6, 2024

This PR includes the initial version of OpenCL pipeline for layers to run on GPU. Following wrappers have been added which uses OpenCL APIs internally:

  • opencl_loader: Loading required OpenCL functions.
  • opencl_context_manager: Getting device details and managing context creation globally.
  • opencl_command_queue_manager: Creation and deletion of global command queue, reading and writing buffers, dispatching kernels.
  • opencl_kernel: Managing kernels and setting arguments.
  • opencl_program: Building and managing OpenCL program.
  • opencl_buffer: Creating, reading and writing data on OpenCL buffer.

opencl_op_interface has been created to handle the workflow of kernel execution.

Tensor level changes:

  • Added cl_interface to handle tensor operations which will be executed on GPU.
  • Added experimental naïve OpenCL kernel for SGEMV which can be useful for testing the initial pipeline.
  • Modified sum and sum_by_batch function signatures to use boolean flag for choosing compute engine (CPU/GPU).

enable-opencl flag incorporated in meson.options

Update (23 Feb 2024):

  • ml::train::LayerComputeEngine enum added to handle compute engine information. Only FullyConnected layer API signature modified as of now.
  • createLayer API modified to propagate compute engine info via factory to layer_node.
  • cl_context created to handle global configuration of OpenCL environment which will create command queue and context for OpenCL and register layers to be run on GPU.
  • Getter and setter for compute engine added to layer_context along with utility to create kernel.
  • Modified build configurations as required.
  • Added UT for cl_context global instance creation with GPU command queue.

opencl_op_interface can be deprecated later. Restored sum and sum_by_batch function signatures as tensor level kernels are not required at this moment. Refactored experimental naïve OpenCL kernel for SGEMV.

Signed-off-by: Debadri Samaddar [email protected]

@taos-ci
Copy link
Collaborator

taos-ci commented Feb 6, 2024

📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #2465. Please a submit 1commit/1PR (one commit per one PR) policy to get comments quickly from reviewers. Your PR must pass all verificiation processes of cibot before starting a review process from reviewers. If you are new member to join this project, please read manuals in documentation folder and wiki page. In order to monitor a progress status of your PR in more detail, visit http://ci.nnstreamer.ai/.

@taos-ci
Copy link
Collaborator

taos-ci commented Feb 6, 2024

:octocat: cibot: @s-debadri, A builder checker could not be completed because one of the checkers is not completed. In order to find out a reason, please go to http://ci.nnstreamer.ai/nntrainer/ci/repo-workers/pr-checker/2465-202402061833290.23417901992798-9fac4504a9442c86c07d1fc1e9dadfb201f8bdf6/.


foreach h : opencl_headers
nntrainer_headers += meson.current_source_dir() / h
endforeach
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add new line at the end of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in next commit

@@ -42,7 +42,8 @@ nntrainer_elements = [
'optimizers',
'tensor',
'utils',
'graph'
'graph',
'opencl'
Copy link
Collaborator

@jijoongmoon jijoongmoon Feb 7, 2024

Choose a reason for hiding this comment

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

This can be optional. how about adding option('enable-opencl', type: 'boolean', value: false) in meson_options.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added related changes in next commit. Updated description.

@taos-ci
Copy link
Collaborator

taos-ci commented Feb 7, 2024

:octocat: cibot: @s-debadri, nntrainer/tensor/cl_operations/cl_sgemv.hpp does not include Doxygen tags such as @file @brief @author @bug. You must include the Doxygen tags in the source code. Please refer to a Doxygen manual at http://github.com/nnstreamer/TAOS-CI/blob/main/ci/doc/doxygen-documentation.md

@taos-ci
Copy link
Collaborator

taos-ci commented Feb 7, 2024

:octocat: cibot: @s-debadri, nntrainer/opencl/opencl_buffer.cpp includes bug(s). Please fix incorrect coding constructs in your commit before entering a review process.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@s-debadri, 💯 All CI checkers are successfully verified. Thanks.

endforeach

foreach h : opencl_headers
nntrainer_headers += meson.current_source_dir() / h
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be better to use .h for header files.


#include <nntrainer_log.h>

namespace nntrainer::internal {
Copy link
Collaborator

@jijoongmoon jijoongmoon Feb 7, 2024

Choose a reason for hiding this comment

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

How about nntrainer::opencl namesapce rather than internal to make it clearer?

#include "opencl_context_manager.hpp"
#include "third_party/cl.h"

namespace nntrainer::internal {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about adding more comments following the oxygen to provide a better understanding?


#include <vector>

#include "opencl_loader.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

please check order.

cl_program prgm = program.GetProgram();
kernel_ = clCreateKernel(prgm, function_name.c_str(), &error_code);
if (!kernel_ || error_code != CL_SUCCESS) {
kernel_ = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

As a doc, clCreateKernel returns null with error code whenever it fails.

@s-debadri s-debadri changed the title [WIP][GPU/OpenCL] OpenCL pipeline for tensor operations to be executed on GPU [WIP][GPU/OpenCL] OpenCL pipeline for layer execution on GPU Feb 23, 2024
Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@s-debadri, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@s-debadri, 💯 All CI checkers are successfully verified. Thanks.

@s-debadri s-debadri force-pushed the gpu_pipeline_core branch 2 times, most recently from d24c2e5 to c4de26a Compare March 6, 2024 08:55
@taos-ci
Copy link
Collaborator

taos-ci commented Mar 6, 2024

:octocat: cibot: @s-debadri, nntrainer/opencl/opencl_buffer.cpp includes bug(s). Please fix incorrect coding constructs in your commit before entering a review process.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@s-debadri, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Member

@DonghakPark DonghakPark left a comment

Choose a reason for hiding this comment

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

Hi you got 3 formatting error

clang-format reports: 3 file(s) not formatted
nntrainer/opencl/opencl_buffer.cpp
nntrainer/opencl/third_party/cl.h
nntrainer/opencl/third_party/cl_platform.h

on here, now our TAOS CI and gitaction CI has different version
so please fomatting based on gitaction CI ?

@DonghakPark DonghakPark changed the title [GPU/OpenCL] OpenCL pipeline for layer execution on GPU [GPU/OpenCL] OpenCL pipeline for layer execution on GPU @open sesame 03/07 10:42 Mar 7, 2024
Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@s-debadri, 💯 All CI checkers are successfully verified. Thanks.

@taos-ci
Copy link
Collaborator

taos-ci commented Mar 7, 2024

:octocat: cibot: @s-debadri, nntrainer/opencl/opencl_buffer.cpp includes bug(s). Please fix incorrect coding constructs in your commit before entering a review process.

@taos-ci
Copy link
Collaborator

taos-ci commented Mar 7, 2024

:octocat: cibot: @s-debadri, nntrainer/opencl/third_party/cl_platform.h does not include Doxygen tags such as @file @brief @author @bug. You must include the Doxygen tags in the source code. Please refer to a Doxygen manual at http://github.com/nnstreamer/TAOS-CI/blob/main/ci/doc/doxygen-documentation.md

@taos-ci
Copy link
Collaborator

taos-ci commented Mar 7, 2024

:octocat: cibot: @s-debadri, nntrainer/opencl/opencl_buffer.cpp includes bug(s). Please fix incorrect coding constructs in your commit before entering a review process.

@DonghakPark
Copy link
Member

@s-debadri
in case of third party code you can ignore doxygen ci error
And if you want to fix, cpp or clang ci error --> you can see details --> git action summary or cmd log

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@s-debadri, 💯 All CI checkers are successfully verified. Thanks.

Fixed CI issues for the following:
Third party files: clang
Non third party files: clang, doxygen

Signed-off-by: Debadri Samaddar <[email protected]>
@taos-ci
Copy link
Collaborator

taos-ci commented Mar 7, 2024

:octocat: cibot: @s-debadri, nntrainer/opencl/third_party/cl_platform.h does not include Doxygen tags such as @file @brief @author @bug. You must include the Doxygen tags in the source code. Please refer to a Doxygen manual at http://github.com/nnstreamer/TAOS-CI/blob/main/ci/doc/doxygen-documentation.md

@taos-ci
Copy link
Collaborator

taos-ci commented Mar 7, 2024

:octocat: cibot: @s-debadri, nntrainer/opencl/opencl_buffer.cpp includes bug(s). Please fix incorrect coding constructs in your commit before entering a review process.

Handled conditions by reducting ifdef checks

Signed-off-by: Debadri Samaddar <[email protected]>
Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@s-debadri, 💯 All CI checkers are successfully verified. Thanks.

@jijoongmoon jijoongmoon merged commit 459810e into nnstreamer:main Mar 7, 2024
27 of 28 checks passed
@skykongkong8
Copy link
Member

I found this commit emits error when using ndk-build in the current main

ld: error: undefined symbol: nntrainer::ClContext::Global()
>>> referenced by layers_dependent_common_tests.cpp:38 (../unittest/layers/layers_dependent_common_tests.cpp:38)
>>>               /home/sungsik/nntrainer/test/obj/local/arm64-v8a/objs/unittest_layers/__/unittest/layers/layers_dependent_common_tests.o:(LayerSemantics_createFromClContext_pn_Test::TestBody())

ld: error: undefined symbol: int const nntrainer::ClContext::registerFactory<nntrainer::Layer>(std::__ndk1::function<std::__ndk1::unique_ptr<nntrainer::Layer, std::__ndk1::default_delete<nntrainer::Layer> > (std::__ndk1::vector<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::allocator<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > > > const&)>, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, int)
>>> referenced by layers_dependent_common_tests.cpp:40 (../unittest/layers/layers_dependent_common_tests.cpp:40)
>>>               /home/sungsik/nntrainer/test/obj/local/arm64-v8a/objs/unittest_layers/__/unittest/layers/layers_dependent_common_tests.o:(LayerSemantics_createFromClContext_pn_Test::TestBody())

ld: error: undefined symbol: nntrainer::opencl::ContextManager::ReleaseContext()
>>> referenced by layer_context.h:829 (/home/sungsik/nntrainer/nntrainer/layers/layer_context.h:829)
>>>               /home/sungsik/nntrainer/test/obj/local/arm64-v8a/objs/unittest_layers/__/unittest/layers/layers_golden_tests.o:(nntrainer::RunLayerContext::~RunLayerContext())
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

@s-debadri
Copy link
Contributor Author

I found this commit emits error when using ndk-build in the current main

ld: error: undefined symbol: nntrainer::ClContext::Global()
>>> referenced by layers_dependent_common_tests.cpp:38 (../unittest/layers/layers_dependent_common_tests.cpp:38)
>>>               /home/sungsik/nntrainer/test/obj/local/arm64-v8a/objs/unittest_layers/__/unittest/layers/layers_dependent_common_tests.o:(LayerSemantics_createFromClContext_pn_Test::TestBody())

ld: error: undefined symbol: int const nntrainer::ClContext::registerFactory<nntrainer::Layer>(std::__ndk1::function<std::__ndk1::unique_ptr<nntrainer::Layer, std::__ndk1::default_delete<nntrainer::Layer> > (std::__ndk1::vector<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::allocator<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > > > const&)>, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, int)
>>> referenced by layers_dependent_common_tests.cpp:40 (../unittest/layers/layers_dependent_common_tests.cpp:40)
>>>               /home/sungsik/nntrainer/test/obj/local/arm64-v8a/objs/unittest_layers/__/unittest/layers/layers_dependent_common_tests.o:(LayerSemantics_createFromClContext_pn_Test::TestBody())

ld: error: undefined symbol: nntrainer::opencl::ContextManager::ReleaseContext()
>>> referenced by layer_context.h:829 (/home/sungsik/nntrainer/nntrainer/layers/layer_context.h:829)
>>>               /home/sungsik/nntrainer/test/obj/local/arm64-v8a/objs/unittest_layers/__/unittest/layers/layers_golden_tests.o:(nntrainer::RunLayerContext::~RunLayerContext())
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

@skykongkong8
This requires ENABLE_OPENCL to be true in meson_options.txt while building libnntrainer.so.
Or, nntrainer/test/jni/Android.mk can be modified as such:

  • Modify setup for unittest_layers and remove -DENABLE_OPENCL=1 from LOCAL_CFLAGS variable.
  • This will disable OpenCL dependency for unittest_layers.

@skykongkong8
Copy link
Member

@s-debadri
Right.. then could you make a PR for that issue?

@s-debadri s-debadri deleted the gpu_pipeline_core branch May 23, 2024 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants