Skip to content

Conversation

@echuraev
Copy link
Contributor

This wrapper helps dynamically loading OpenCL library. It allows us to avoid of looking for and copying OpenCL library to host, looking for OpenCL SDK.

cc: @elvin-n, @masahi, @csullivan

@tvm-bot
Copy link
Collaborator

tvm-bot commented Nov 11, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@echuraev echuraev force-pushed the echuraev/libopencl_wrapper branch from 548d1cf to fb3f5a6 Compare November 11, 2022 10:25
@echuraev echuraev marked this pull request as draft November 11, 2022 11:10
@echuraev echuraev force-pushed the echuraev/libopencl_wrapper branch from fb3f5a6 to 6614443 Compare November 11, 2022 12:42
@echuraev echuraev marked this pull request as ready for review November 11, 2022 12:42
@masahi
Copy link
Member

masahi commented Nov 14, 2022

@elvin-n Can you review this?

@echuraev echuraev force-pushed the echuraev/libopencl_wrapper branch from 446941f to 8ecacf8 Compare November 14, 2022 09:19
Copy link
Contributor

@csullivan csullivan left a comment

Choose a reason for hiding this comment

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

Many thanks for this great improvement to the user experience of compiling and running code on remote OpenCL devices @echuraev!

Comment on lines 20 to 24
/*!
* \file opencl_wrapper.cc
*/
Copy link
Contributor

@csullivan csullivan Nov 14, 2022

Choose a reason for hiding this comment

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

Can we note the version of opencl for which this wrapper is applicable?

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 information about OpenCL version. Currently, this wrapper is applicable for OpenCL 1.2. Because it is version which is used in TVM. But we can easily uplift this version, then it will be necessary.

@echuraev
Copy link
Contributor Author

@tvm-bot rerun

@echuraev
Copy link
Contributor Author

@tvm-bot rerun

This wrapper helps dynamically loading OpenCL library. It allows us to
avoid of looking for and copying OpenCL library to host, looking for
OpenCL SDK.
Also, use OpenCL wrapper by default and fix Windows build
@echuraev echuraev force-pushed the echuraev/libopencl_wrapper branch from 0df05af to 0453286 Compare November 15, 2022 17:55
@areusch
Copy link
Contributor

areusch commented Nov 16, 2022

We discussed this in the TVM community meeting this morning. Here are notes:

  • Initially we developed support for OpenCL without statically linking to the library; for mobile, need to manually download the SDK to your phone, and compile TVM linking against it.
  • Alternate approach: the API is stable and we don't use very many symbols; can we develop a wrapper around OpenCL that can be dynamically loaded?
  • Two options now:
    1. OPENCL is ON: cmake tries to find OpenCL SDK somewhere at compile time
    2. OpenCL path is specified: pins the headers to a specific location
  • New proposed option:
    • ON now means to use the wrapper in this PR to automatically find the library at runtime and load it dynamically
    • approach is also used in TFLite
  • @areusch: can we detect the case where, at runtime, the user is using a version of libOpenCL.so that is too old?
    • Currently we return a call-specific error code; this is tricky
    • @echuraev: Yeah we can do this
  • The way in which we've included OpenCL headers into 3rdparty is ok.

echuraev added a commit to echuraev/tvm that referenced this pull request Nov 18, 2022
As it was mentioned in apache#13362, it would be nice to add check when the
user is using a version of libOpenCL.so that is too old.

In this PR we introduce this functionality. In the `init` method, we
traverse through all OpenCL devices and check their version. If the
version is older than the target version in TVM, then we notify the user
that we will skip this device. We cannot throw any exception from method
`init` because it is possible that you have compiled host code with
OpenCL support, but the host device won't have any OpenCL device which
is supported by TVM (e.g. they all have too old version of
libOpenCL.so). From OpenCL codegen we call function OpenCLModuleCreate.
In the OpenCLModuleCreate init function might be called and in this case
an exception will be generated on the host side although that the target
device might be supported by TVM. This is why we don't throw any
exceptions in the init function.

If in the runtime we use some OpenCL methods and the list of the devices
is empty, then we will generate an exception and notify user that
possible reason is because version of libOpenCL.so is too old.
echuraev added a commit to echuraev/tvm that referenced this pull request Nov 18, 2022
As it was mentioned in apache#13362, it would be nice to add check when the
user is using a version of libOpenCL.so that is too old.

In this PR we introduce this functionality. In the `init` method, we
traverse through all OpenCL devices and check their version. If the
version is older than the target version in TVM, then we notify the user
that we will skip this device. We cannot throw any exception from method
`init` because it is possible that you have compiled host code with
OpenCL support, but the host device won't have any OpenCL device which
is supported by TVM (e.g. they all have too old version of
libOpenCL.so). From OpenCL codegen we call function OpenCLModuleCreate.
In the OpenCLModuleCreate init function might be called and in this case
an exception will be generated on the host side although that the target
device might be supported by TVM. This is why we don't throw any
exceptions in the init function.

If in the runtime we use some OpenCL methods and the list of the devices
is empty, then we will generate an exception and notify user that
possible reason is because version of libOpenCL.so is too old.
echuraev added a commit to echuraev/tvm that referenced this pull request Nov 18, 2022
As it was mentioned in apache#13362, it would be nice to add check when the
user is using a version of libOpenCL.so that is too old.

In this PR we introduce this functionality. In the `init` method, we
traverse through all OpenCL devices and check their version. If the
version is older than the target version in TVM, then we notify the user
that we will skip this device. We cannot throw any exception from method
`init` because it is possible that you have compiled host code with
OpenCL support, but the host device won't have any OpenCL device which
is supported by TVM (e.g. they all have too old version of
libOpenCL.so). From OpenCL codegen we call function OpenCLModuleCreate.
In the OpenCLModuleCreate init function might be called and in this case
an exception will be generated on the host side although that the target
device might be supported by TVM. This is why we don't throw any
exceptions in the init function.

If in the runtime we use some OpenCL methods and the list of the devices
is empty, then we will generate an exception and notify user that
possible reason is because version of libOpenCL.so is too old.
masahi pushed a commit that referenced this pull request Nov 18, 2022
As it was mentioned in #13362, it would be nice to add check when the
user is using a version of libOpenCL.so that is too old.

In this PR we introduce this functionality. In the `init` method, we
traverse through all OpenCL devices and check their version. If the
version is older than the target version in TVM, then we notify the user
that we will skip this device. We cannot throw any exception from method
`init` because it is possible that you have compiled host code with
OpenCL support, but the host device won't have any OpenCL device which
is supported by TVM (e.g. they all have too old version of
libOpenCL.so). From OpenCL codegen we call function OpenCLModuleCreate.
In the OpenCLModuleCreate init function might be called and in this case
an exception will be generated on the host side although that the target
device might be supported by TVM. This is why we don't throw any
exceptions in the init function.

If in the runtime we use some OpenCL methods and the list of the devices
is empty, then we will generate an exception and notify user that
possible reason is because version of libOpenCL.so is too old.
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
* [OpenCL] Introduce OpenCL wrapper to TVM

This wrapper helps dynamically loading OpenCL library. It allows us to
avoid of looking for and copying OpenCL library to host, looking for
OpenCL SDK.

* Update apps and documentation

* Apply comments

* Apply comments and fix Android build

Also, use OpenCL wrapper by default and fix Windows build

* Apply comments

* Update LICENSE file
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
As it was mentioned in apache#13362, it would be nice to add check when the
user is using a version of libOpenCL.so that is too old.

In this PR we introduce this functionality. In the `init` method, we
traverse through all OpenCL devices and check their version. If the
version is older than the target version in TVM, then we notify the user
that we will skip this device. We cannot throw any exception from method
`init` because it is possible that you have compiled host code with
OpenCL support, but the host device won't have any OpenCL device which
is supported by TVM (e.g. they all have too old version of
libOpenCL.so). From OpenCL codegen we call function OpenCLModuleCreate.
In the OpenCLModuleCreate init function might be called and in this case
an exception will be generated on the host side although that the target
device might be supported by TVM. This is why we don't throw any
exceptions in the init function.

If in the runtime we use some OpenCL methods and the list of the devices
is empty, then we will generate an exception and notify user that
possible reason is because version of libOpenCL.so is too old.
@echuraev echuraev deleted the echuraev/libopencl_wrapper branch April 14, 2023 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants